Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
es5-class-ployfill
Advanced tools
Readme
Use Class-likely in es5
Inspired by http://ejohn.org/blog/simple-javascript-inheritance/
Node.js 4 or higher
$ npm install es5-class-ployfill --save
var Class = require('es5-class-ployfill');
// Shape
var Shape = Class.extend({
constructor: function() {
this.x = 0;
this.y = 0;
},
move: function(x, y) {
this.x += x;
this.y += y;
console.info('Shape moved.');
},
echo: function() {
console.log('I am Shape.');
}
});
// Rectangle
var Rectangle = Shape.extend({
constructor: function(w, h) {
this.w = w;
this.h = h;
this._super();
},
move: function(x, y) {
this._super(x, y);
console.info('Rectangle moved.');
},
area: function() {
console.log('Area is', this.w * this.h);
},
echo: function() {
console.log('I am Rectangle.');
}
});
// Square
var Square = Rectangle.extend({
constructor: function(w) {
this._super(w, w);
},
echo: function() {
console.log('I am Square.');
}
});
var rect = new Rectangle(2, 4);
var square = new Square(4);
console.log('Is rect an instance of Rectangle?', rect instanceof Rectangle);// true
console.log('Is rect an instance of Shape?', rect instanceof Shape);// true
console.log('Is rect an instance of Square?', rect instanceof Square);// false
rect.echo(); // Outputs, 'I am Rectange.'
rect.move(1, 1); // Outputs, 'Shape moved. Rectangle moved.'
rect.area(); // Outputs, 'Area is 8'
console.log('Is square an instance of Square?', square instanceof Square);// true
console.log('Is square an instance of Rectangle?', square instanceof Rectangle);// true
console.log('Is square an instance of Shape?', square instanceof Shape);// true
square.echo(); // Outputs, 'I am Square.'
square.area(); // Outputs, 'Area is 16'
Class.extend(proto)
Define Function prototype, especially proto.constructor
is Function constructor
FAQs
Use Class-likely in es5
The npm package es5-class-ployfill receives a total of 3 weekly downloads. As such, es5-class-ployfill popularity was classified as not popular.
We found that es5-class-ployfill 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
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.