Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Standardized class
syntax
is coming
in ECMAScript 6, supposedly, but until then I need a class factory that fills the gap.
For me that means (in no particular order):
super
)static
propertiesstatic
constructorsI have no delusions of persuading the world to use this tool. Just try
npm search inheritance
some time to see how many other people have come
up with solutions that work for them.
If you have a special interest in the tired me-too sport of pure-JavaScript class factory implementations, you might find this one interesting for its solutions to each of the requirements listed above, particularly the lazy (just-in-time) population of prototype properties.
Note that I did not mention privacy enforcement as a requirement. If you
need a mechanism like the private
keyword in other languages, I have a
separate project that works
seamlessly alongside this one.
From NPM:
npm install cls
From GitHub:
cd path/to/node_modules
git clone git://github.com/benjamn/cls.git
cd cls
npm install .
One example will have to suffice for now:
var cls = require("cls");
var BaseClass = cls.extend({
init: function(a, b) {
this.sum = a + b;
},
getSum: function() {
return this.sum;
},
statics: {
name: "BaseClass",
init: function(cls) {
cls.zero = new cls(0, 0);
}
}
});
var SubClass = BaseClass.extend({
init: function(arg) {
this._super(arg, arg);
this.sum += 1;
},
statics: {
name: "SubClass"
}
});
assert(BaseClass.name === "BaseClass");
assert(SubClass.name === "SubClass");
assert(new BaseClass(2).getSum() === 4);
assert(new SubClass(2).getSum() === 5);
assert(SubClass.zero !== BaseClass.zero);
assert(SubClass.zero instanceof SubClass);
assert(SubClass.zero.getSum() === 1);
For more complex examples, see test/run.js
.
FAQs
Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.
The npm package cls receives a total of 1,157 weekly downloads. As such, cls popularity was classified as popular.
We found that cls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.