Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
appolo-class
Advanced tools
Simple and powerful class system for node js
npm install appolo-class --save
var Rectangle = Class.define({
area: function () {
return 25;
}
});
var rectangle = new Rectangle();
creating class with constractor
var Rectangle = Class.define({
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var rectangle = new Rectangle(5, 5);
console.log(rectangle.area()) // 25
var Rectangle = Class.define({
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var Square = Class.define({
$config: {
extends: Rectangle
},
constructor: function (side) {
this.callParent(this, side, side);
}
});
var square = new Square(6);
console.log(square.area()) // 36
you can also use Class.define
fucntion
var Rectangle = Class.define({
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var Square = Rectangle.define({
constructor: function (side) {
this.callParent(side, side);
}
});
var square = new Square(6);
console.log(square.area()) // 36
use this.callParent
function to call the parent method
var Rectangle = Class.define({
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var Square = Rectangle.define({
constructor: function (side) {
this.callParent(side, side);
}
});
var Cube = Square.define({
constructor: function (side) {
this.callParent(side);
this.side = side;
},
area: function () {
return 6 * this.callParent()
},
volume: function () {
return Math.pow(this.side,3);
}
});
var cube = new Cube(5);
console.log(cube.area()) //150;
console.log(cube.volume()) //125;
var Rectangle = Class.define({
$config: {
statics: {
MIN_SIDE: 1,
MAX_SIDE: 150
}
},
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
console.log(Rectangle.MIN_SIDE) //1;
var rectangle = new Rectangle(5, 5);
console.log(rectangle.MIN_SIDE.should.equal(1)) //1;
used to add protoype functions from other classes
var Events = Class.define({
bind: function (event, fn) {
return true;
},
unbind: function (event, fn) {
return true;
}
});
var Rectangle = Class.define({
$config: {
mixins: [Events]
},
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var rectangle = new Rectangle(5, 5);
rectangle.bind('test',function(){})
rectangle.unbind('test',function(){})
create class on the global scope
Class.define('Test.Position.Base', {
constructor: function (symbol, amount, side) {
this.symbol = symbol;
this.amount = amount;
this.side = side;
}
});
Position.define('Test.Position.Long', {
constructor: function (symbol, amount) {
this.callParent( symbol, amount, 2);
}
});
Position.define("Test.Position.Short", {
constructor: function (symbol, amount) {
this.callParent(symbol, amount, 2);
}
});
var short = new Test.Position.Short();
var long = new Test.Position.Long();
you can define the class name
var Position = Class.define({
constructor: function (symbol, amount, side) {
this.symbol = symbol;
this.amount = amount;
this.side = side;
}
});
var Long = Position.define({
$config: {
name: "long"
},
constructor: function (symbol, amount) {
this.callParent( symbol, amount, 2);
}
});
var Short = Position.define({
$config: {
name: "short"
},
constructor: function (symbol, amount) {
this.callParent(symbol, amount, 2);
}
});
var short = new Short();
var long = new Long();
consloe.log(short.constructor.name) // short
console.log(long.constructor.name) //long;
define properties with getter and setter functions. if a property in defined to be a member and a getter or setter is not implemented then erro will be trown
var Rectangle = Class.define({
$config: {
members: ['area','name']
},
constructor: function (width, height) {
this.height = height;
this.width = width;
},
getArea: function () {
return this.width * this.height;
},
getName:function(){
return this._name;
},
setName:function(value){
this._name = value;
}
});
var rectangle = new Rectangle(5, 5);
console.log(rectangle.area) //25;
rectangle.area = 10 // error not implemented
you can your custom plugins to the class system by adding callback function
the function will be called with 3 arguments
config
- config object of the classklass
- class referanceparent
- parent class referanceClass.addPlugin(function(config,klass,parent){
//do something
});
grunt test
The appolo class
library is released under the MIT license. So feel free to modify and distribute it as you wish.
FAQs
simple and powerful class system for node js
We found that appolo-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.