src/n13.js
/**
             * @private
             * Applies properties to new created class and call feature handlers for special parameters
             * like mixins, statics, extend and so on.
             * @param {Function} cl Class we need to apply
             * @param {Object}   cl.base Reference to the parent's prototype
             * @param {Object} properties Properties
             */
@private
Applies properties to new created class and call feature handlers for special parameters
like mixins, statics, extend and so on.
@param {Function} cl Class we need to apply
@param {Object}   cl.base Reference to the parent's prototype
@param {Object} properties Properties
@private Applies properties to new created class and call feature handlers for special parameters like mixins statics extend and so on . @param { Function } cl Class we need to apply @param { Object } cl . base Reference to the parent ' s prototype @param { Object } properties Properties
function applyProperties(cl, properties) {
                function addStatics(cl, statics) {
                    var s;
                    var stat;
                    for (s in statics) {
                        if (statics.hasOwnProperty(s)) {
                            stat = statics[s];
                            if (cl[s] === undefined) {
                                if (isFunction(stat)) {
                                     Name of the property, where we store current function name. It will be used in
                                     callParent() method, which calls same method from parent class.
                                    stat.fn   = s;
                                    stat.base = cl.base;
                                    stat.cl   = cl.prototype;
                                }
                                cl[s] = stat;
                            }
                        }
                    }
                }
                /**
                 * @private
                 * Mixin classes handler. Adds methods/properties from mixins to the class function. Analog of
                 * mixins in other OOP languages. If some methods/properties are already exist, then they
                 * will be skipped. Very important moment here is that All methods will be copied, except init()
                 * and destroy(). These methods should be called using callMixin() method or manually, using
                 * self or class function (Class.prototype.destroy.apply(this, [args])) Example:
                 *
                 *     N13.define('Mixin', {
                 *         mixMethod: function () {return this.mix;},
                 *         mix      : 'mixin'
                 *     });
                 *     N13.define('Class', {
                 *         mixins: {
                 *             mix: 'Mixin'
                 *         }
                 *     });
                 *
                 *     var cl = new Class();
                 *     cl.mixMethod()   'mixin'
                 *     cl.mix;          'mixin'
                 *
                 * @param {Function} cl         Class, we need mixins to add
                 * @param {Object}   cl.base    Reference to the class parent's prototype
                 * @param {Object}   mixins     Mixins map
                 * @param {Object}   properties Properties sent by second parameter in N13.define method
                 */
                function addMixins(cl, mixins, properties) {
                    var clProto  = cl.prototype;
                    var protoMix = clProto.mixins = {};
                    var m;
                    var i;
                    var mixinProto;
                    var mixin;
                    var mixinCl;
                    var mixinBase;
                    var configs;
                    var cfg;
                    for (i in mixins) {
                        if (mixins.hasOwnProperty(i)) {
                             Save mixins map in the "mixins" property
                            mixinCl     = ns(mixins[i]);
                            mixinBase   = mixinCl.base;
                            protoMix[i] = mixinProto = mixinCl.prototype;
                            for (m in mixinProto) {
                                mixin = mixinProto[m];
                                 It's possible to apply configuration from mixin. If main class doesn't
                                 contain properties, which mixin does, then they may be copied into main one
                                if (m === 'configs') {
                                    configs = properties.configs = properties.configs || {};
                                     Walks through config properties and apply only unique for main class
                                    for (cfg in mixin) {
                                         Applies config only if main class doesn't contain same config
                                        if (mixin.hasOwnProperty(cfg) && configs[cfg] === undefined) {
                                            configs[cfg] = mixin[cfg];
                                        }
                                    }
                                     We should copy mixed method, only in case when main class doesn't contain them
                                } else if (!clProto.hasOwnProperty(m) && properties[m] === undefined && m !== 'init' && m !== 'destroy') {
                                    if (isFunction(mixin)) {
                                         Name of the property, where we store current function name. It will be used in
                                         callParent() method, which calls same method from parent class.
                                        if (mixin.fn === undefined) {
                                            mixin.fn = m;
                                             Important!!! If current class uses mixin with some hierarchy inside and
                                             current class has no some method (e.g.: method()) which mixin has,
                                             then if later we call callParent() in the method() of current class,
                                             super method from mixin will be called. You should understand, that
                                             if current class contains this method in superclass, it will not be
                                             called.
                                            mixin.base = mixinBase.hasOwnProperty(m) ? mixinBase : cl.base;
                                            mixin.cl = mixinCl.prototype;
                                        }
                                    }
                                    clProto[m] = mixin;
                                }
                            }
                        }
                    }
                }
                /**
                 * @private
                 * Configuration handler. Adds configuration properties into the class prototype. You should use
                 * special property for this called "configs".
                 * Here is an example:
                 *
                 *     N13.define('App.Class', {
                 *         configs: {
                 *             cfg1: 'value1',
                 *             cfg2: 'value2'
                 *         }
                 *     });
                 *
                 *     var cl  = new App.Class();
                 *     var cl1 = new App.Class({cfg1: 'hello'});
                 *     cl.cfg1;   'value1'
                 *     cl.cfg2;   'value2'
                 *     cl1.cfg1;  'hello'
                 *     cl1.cfg2;  'value2'
                 *
                 * @param {{base: Object}} cl Class, we need configs to add
                 * @param {Object} configs Configuration object
                 */
                function addConfigs(cl, configs) {
                    var clProto = cl.prototype;
                    var cfg;
                    var config;
                    for (cfg in configs) {
                        if (configs.hasOwnProperty(cfg)) {
                            config = configs[cfg];
                             Name of the property, where we store current function name. It will be used in
                             callParent() method, which calls same method from parent class.
                            if (isFunction(config)) {
                                config.fn   = cfg;
                                config.base = cl.base;
                                config.cl   = cl.prototype;
                            }
                            clProto[cfg] = config;
                        }
                    }
                     We should store original configuration in prototype
                    clProto.configs = configs;
                }
                var proto    = cl.prototype;
                 Here is a map of supported Object Oriented features. This list shouldn't contain "extend" property,
                 because we need it later for inheritance.
                var features = {
                    statics : addStatics,
                    mixins  : addMixins,
                    configs : addConfigs,
                     We need only exclude "requires" property from child class, because we already have processed it.
                    requires: emptyFn
                };
                var property;
                var p;
                for (p in properties) {
                    if (properties.hasOwnProperty(p)) {
                        property = properties[p];
                         This is features handler. If current property is a feature (e.g.: mixins, statics,...), then
                         it calls special handler function, which do the job (e.g.: adds all mixins into the class).
                         Finally, this property will not appear in the class.
                        if (features.hasOwnProperty(p)) {
                            features[p](cl, property, properties);
                        } else {
                            if (isFunction(property)) {
                                 Name of the property, where we store current function name. It will be used in
                                 callParent() method, which calls same method from parent class.
                                property.fn   = p;
                                property.base = cl.base;
                                property.cl   = cl.prototype;
                            }
                            proto[p] = property;
                        }
                    }
                }
                proto.finished = true;
            }
function applyProperties ( cl , properties ) { function addStatics ( cl , statics ) { var s ; var stat ; for ( s in statics ) { if ( statics . hasOwnProperty ( s ) ) { stat = statics [ s ] ; if ( cl [ s ] === undefined ) { if ( isFunction ( stat ) ) { stat . fn = s ; stat . base = cl . base ; stat . cl = cl . prototype ; } cl [ s ] = stat ; } } } } function addMixins ( cl , mixins , properties ) { var clProto = cl . prototype ; var protoMix = clProto . mixins = { } ; var m ; var i ; var mixinProto ; var mixin ; var mixinCl ; var mixinBase ; var configs ; var cfg ; for ( i in mixins ) { if ( mixins . hasOwnProperty ( i ) ) { mixinCl = ns ( mixins [ i ] ) ; mixinBase = mixinCl . base ; protoMix [ i ] = mixinProto = mixinCl . prototype ; for ( m in mixinProto ) { mixin = mixinProto [ m ] ; if ( m === 'configs' ) { configs = properties . configs = properties . configs || { } ; for ( cfg in mixin ) { if ( mixin . hasOwnProperty ( cfg ) && configs [ cfg ] === undefined ) { configs [ cfg ] = mixin [ cfg ] ; } } } else if ( ! clProto . hasOwnProperty ( m ) && properties [ m ] === undefined && m !== 'init' && m !== 'destroy' ) { if ( isFunction ( mixin ) ) { if ( mixin . fn === undefined ) { mixin . fn = m ; mixin . base = mixinBase . hasOwnProperty ( m ) ? mixinBase : cl . base ; mixin . cl = mixinCl . prototype ; } } clProto [ m ] = mixin ; } } } } } function addConfigs ( cl , configs ) { var clProto = cl . prototype ; var cfg ; var config ; for ( cfg in configs ) { if ( configs . hasOwnProperty ( cfg ) ) { config = configs [ cfg ] ; if ( isFunction ( config ) ) { config . fn = cfg ; config . base = cl . base ; config . cl = cl . prototype ; } clProto [ cfg ] = config ; } } clProto . configs = configs ; } var proto = cl . prototype ; var features = { statics : addStatics , mixins : addMixins , configs : addConfigs , requires : emptyFn } ; var property ; var p ; for ( p in properties ) { if ( properties . hasOwnProperty ( p ) ) { property = properties [ p ] ; if ( features . hasOwnProperty ( p ) ) { features [ p ] ( cl , property , properties ) ; } else { if ( isFunction ( property ) ) { property . fn = p ; property . base = cl . base ; property . cl = cl . prototype ; } proto [ p ] = property ; } } } proto . finished = true ; }
@private
 Applies properties to new created class and call feature handlers for special parameters
 like mixins, statics, extend and so on.
@private Applies properties to new created class and call feature handlers for special parameters like mixins statics extend and so on .
/**
                 * @private
                 * Statics properties/methods handler. Adds statics into the class function. Analog of
                 * statics in other OOP languages. Example:
                 *
                 *     N13.define('Class', {
                 *         statics: {
                 *             prop  : 1,
                 *             method: function () {return this.prop;}
                 *         }
                 *     });
                 *
                 *     Class.prop;     // 1
                 *     Class.method(); //
                 *
                 * @param {Function} cl      Class, we need statics to add
                 * @param {Object}   cl.base Reference to the class parent's prototype
                 * @param {Object}   statics Statics map
                 */ // // Name of the property, where we store current function name. It will be used in // callParent() method, which calls same method from parent class. // /**
                 * @private
                 * Mixin classes handler. Adds methods/properties from mixins to the class function. Analog of
                 * mixins in other OOP languages. If some methods/properties are already exist, then they
                 * will be skipped. Very important moment here is that All methods will be copied, except init()
                 * and destroy(). These methods should be called using callMixin() method or manually, using
                 * self or class function (Class.prototype.destroy.apply(this, [args])) Example:
                 *
                 *     N13.define('Mixin', {
                 *         mixMethod: function () {return this.mix;},
                 *         mix      : 'mixin'
                 *     });
                 *     N13.define('Class', {
                 *         mixins: {
                 *             mix: 'Mixin'
                 *         }
                 *     });
                 *
                 *     var cl = new Class();
                 *     cl.mixMethod()  // 'mixin'
                 *     cl.mix;         // 'mixin'
                 *
                 * @param {Function} cl         Class, we need mixins to add
                 * @param {Object}   cl.base    Reference to the class parent's prototype
                 * @param {Object}   mixins     Mixins map
                 * @param {Object}   properties Properties sent by second parameter in N13.define method
                 */ // // Save mixins map in the "mixins" property // // // It's possible to apply configuration from mixin. If main class doesn't // contain properties, which mixin does, then they may be copied into main one // // // Walks through config properties and apply only unique for main class // // // Applies config only if main class doesn't contain same config // // // We should copy mixed method, only in case when main class doesn't contain them // // // Name of the property, where we store current function name. It will be used in // callParent() method, which calls same method from parent class. // // // Important!!! If current class uses mixin with some hierarchy inside and // current class has no some method (e.g.: method()) which mixin has, // then if later we call callParent() in the method() of current class, // super method from mixin will be called. You should understand, that // if current class contains this method in superclass, it will not be // called. // /**
                 * @private
                 * Configuration handler. Adds configuration properties into the class prototype. You should use
                 * special property for this called "configs".
                 * Here is an example:
                 *
                 *     N13.define('App.Class', {
                 *         configs: {
                 *             cfg1: 'value1',
                 *             cfg2: 'value2'
                 *         }
                 *     });
                 *
                 *     var cl  = new App.Class();
                 *     var cl1 = new App.Class({cfg1: 'hello'});
                 *     cl.cfg1;  // 'value1'
                 *     cl.cfg2;  // 'value2'
                 *     cl1.cfg1; // 'hello'
                 *     cl1.cfg2; // 'value2'
                 *
                 * @param {{base: Object}} cl Class, we need configs to add
                 * @param {Object} configs Configuration object
                 */ // // Name of the property, where we store current function name. It will be used in // callParent() method, which calls same method from parent class. // // // We should store original configuration in prototype // // // Here is a map of supported Object Oriented features. This list shouldn't contain "extend" property, // because we need it later for inheritance. // // // We need only exclude "requires" property from child class, because we already have processed it. // // // This is features handler. If current property is a feature (e.g.: mixins, statics,...), then // it calls special handler function, which do the job (e.g.: adds all mixins into the class). // Finally, this property will not appear in the class. // // // Name of the property, where we store current function name. It will be used in // callParent() method, which calls same method from parent class. // /**
                 * {Boolean} It means that this class is fully created. It also means that all dependencies has loaded.
                 */