https://github.com/duzun/classifyed.js
A tiny yet powerful lib for creating extensible JS Classes.
https://github.com/duzun/classifyed.js
Last synced: 6 months ago
JSON representation
A tiny yet powerful lib for creating extensible JS Classes.
- Host: GitHub
- URL: https://github.com/duzun/classifyed.js
- Owner: duzun
- License: mit
- Created: 2015-04-04T22:50:22.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-09-09T14:15:01.000Z (about 5 years ago)
- Last Synced: 2025-03-30T11:34:27.791Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# classifyed.js
A tiny yet powerful lib to create extensible JS Classes,
with an elegant way of calling parent methods.# Usage
```javascript
var MyClass = Classifyed.extend({
constructor: function() { ... },
doFoo: function () { ... }
},
{
type: 'MyClass',
staticFoo: function () {
// This is a static method
}
});var SuperClass = MyClass.extend({
constructor: function(){
this.__super__('constructor', arguments); // call parent constructor
// Continue with the constructor...
},
doFoo: function () {
this.__super__('doFoo', arguments); // call parent method
// Do stuff
}
},
{
type: 'SuperClass',
staticFoo: function () {
this.__super__.constructor.staticFoo(); // call parent static method
this.parent().staticFoo(); // same as previous
}
});var myObj = new SuperClass();
myObj.doFoo();
myObj.__super__('doFoo');console.log(myObj.constructor.type); // 'MyClass'
console.log(myObj.constructor.__super__.constructor.type); // 'SuperClass'
console.log(myObj.constructor.parent().type); // 'SuperClass' again```