Package Exports
- classx
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (classx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ClassX
Basic module that provide Backbone like extend with _super functionality. Also mixins.
- extend - you can extend any of your class
- _super - easy invoke parent's methods
- mixins - mix any object to your class
##Usage ####Extend
/**
* @class Note
* @extends ClassX
*/
var Note = ClassX.extend({
/**
* @private
*/
_defineProperties: function () {
this._super();
/**
* @type {Date}
* @private
*/
this._dateCreation = this._options.dateCreation || new Date();
},
/**
* @constructor
* @protected
*/
_initialize: function() {
this._super();
console.log('This note was created ' + this._dateCreation.getTime());
}
});
/**
* @class PrivateNote
* @extends Note
*/
var PrivateNote = Note.extend({
/**
* @constructor
* @protected
*/
_initialize: function() {
this._super();
console.log('No one can see this.');
}
});
var note = new Note({dateCreation: new Date(1991)}); // This note was created ...
var secretNote = new PrivateNote(); // This note was created ... No one can see this.
####Mixins Mixins are common objects that you can mix into any of your class.
/**
* @mixin WithEncryption
*/
var WithEncryption = {
encrypt: function () {
console.log('encrypted!');
}
}
/**
* @class ClassWithEncryption
* @mixes WithEncryption
*/
var ClassWithEncryption = ClassX.mix(WithEncryption).extend({
/**
* @constructor
* @protected
*/
_initialize: function() {
this._super();
this.encrypt();
}
});
var instance = new ClassWithEncryption(); // encrypted!
##Install
npm install objectx
##Run tests
mocha --reporter spec