0.2.0 • Published 10 years ago

classx v0.2.0

Weekly downloads
3
License
GPL-2.0
Repository
github
Last release
10 years ago

ClassX

travis-ci.org

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
0.2.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago