objectjs
Extendable object in javascript
Installing
npm install objectjs
Using
var ObjectJs = ; ///////////////////////////////////////////////////// Create object A///////////////////////////////////////////////////A = ObjectJs; // A.init will be called automatically// A.value is equal 0// A.get() will return 0// if A.set(100) then A.value and A.get() will be equal 100 ///////////////////////////////////////////////////// Extend A object///////////////////////////////////////////////////A; // A.value is equal 200// A.get() is equal `value=200`. `this._super` will refer to parent function which return `this.value`// A.test() is equal `hello moto`
Note:
this._super()
does not work inasync
because it will be cleared up at the end of the function. You may need to usevar _super = this._super
before callasync
.- You can extend many levels as you want.
- Be careful with
this
object. Take advantage of the best practice below:
License
MIT - Copyright (c) 2014 Angularfiy.org & HenryTao.