inherit plugin with no dependencies [only for morden browsers]
modified from https://raw.github.com/dfilatov/jquery-plugins/master/src/jquery.inherit/jquery.inherit.js
if you want to support IE6-8,use the difference between this repo and the repo above.
Plugin provides "class" and inheritance implementation.
It brings some syntax sugar for "class" declarations, constructors, "super" calls and static members.
Install
node: npm install inherit-js
bower: bower install inherit-js
Usage
var inherit = require('inherit');
var MyClass = $.inherit({
[name: 'ClassName'],
[base: ParentClass],
proto: prototypeMembers,
[statics: staticMembers]
});
Example
var A = inherit({
name: 'A',
proto: {
__constructor : function(property) {
this.property = property;
},
getProperty : function() {
return this.property + ' of instanceA';
},
getType : function() {
return 'A';
},
getStaticProperty : function() {
return this.__self.staticMember;
}
},
statics:{
staticProperty : 'staticA',
staticMethod : function() {
return this.staticProperty;
}
}
});
var B = $.inherit({
name:'B',
base: A,
proto: {
getProperty : function() {
return this.property + ' of instanceB';
},
getType : function() {
return this.__base() + 'B';
}
},
statics: {
staticMethod : function() {
return this.__base() + ' of staticB';
}
}
});
var instanceOfA = new A('property');
var instanceOfB = new B('property');
instanceOfB instanceof B;
instanceOfB instanceof A;
instanceOfB.getProperty();
instanceOfB.getType();
B.staticMethod();