The class4js module is for class-driven development in JavaScript. It allows to emulate classes in JavaScript. Module is based on ECMAScript 5 standart and implements open/close principle: "A module should be open for extension but closed for modifications". class4js is free software distributed under the terms of the GNU General Public License version 3 and can be used with node.js, modern web browsers and even with PhantomJS.
Current version: 1.9.2
Download DocumentationPlainSimple class example
var Shape = $class({
__construct__: function () {
this.__x = 0;
this.__y = 0;
},
x: {
get: function () {
return this.__x;
},
set: function (value) {
this.__x = value;
}
},
y: {
get: function () {
return this.__y;
},
set: function (value) {
this.__y = value;
}
},
draw: function () {
console.log("Drawing shape at: (" + this.x + ", " + this.y + ")");
},
moveTo: function (x, y) {
this.x = x;
this.y = y;
}
});
var shape = new Shape({ x: 100, y: 100 });
shape.moveTo(120, 85);
shape.draw();
Output
Drawing shape at: (120, 85)