classes.js
function (prototypes, force) {
        var instance, proto, names, l, i, replaceMap, protectedMap, name, nameInProto, finalName, propDescriptor, extraInfo;
        if (!prototypes) {
            return;
        }
        instance = this; // the Class
        proto = instance.prototype;
        names = Object.getOwnPropertyNames(prototypes);
        l = names.length;
        i = -1;
        replaceMap = arguments[2] || REPLACE_CLASS_METHODS; // hidden feature, used by itags

        protectedMap = arguments[3] || PROTECTED_CLASS_METHODS; // hidden feature, used by itags
        while (++i < l) {
            name = names[i];
            finalName = replaceMap[name] || name;
            nameInProto = (finalName in proto);
            if (!PROTO_RESERVED_NAMES[finalName] && !protectedMap[finalName] && (!nameInProto || force)) {
                // if nameInProto: set the property, but also backup for chaining using $$orig
                propDescriptor = Object.getOwnPropertyDescriptor(prototypes, name);
                if (!propDescriptor.writable) {
                    console.info(NAME+'mergePrototypes will set property of '+name+' without its property-descriptor: for it is an unwritable property.');
                    proto[finalName] = prototypes[name];
                }
                else {
                    // adding prototypes[name] into $$orig:
                    instance.$$orig[finalName] || (instance.$$orig[finalName]=[]);
                    instance.$$orig[finalName][instance.$$orig[finalName].length] = prototypes[name];
                    if (typeof prototypes[name] === 'function') {
    /*jshint -W083 */
                        propDescriptor.value = (function (originalMethodName, finalMethodName) {
                            return function () {
    /*jshint +W083 */
                                // this.$own = prot;
                                // this.$origMethods = instance.$$orig[finalMethodName];
                                var context, classCarierBkp, methodClassCarierBkp, origPropBkp, returnValue;
                                // in some specific situations, this method is called without context.
                                // can't figure out why (it happens when itable changes some of its its item-values)
                                // probably reasson is that itable.model.items is not the same as itable.getData('_items')
                                // anyway: to prevent errors here, we must return when there is no context:
                                context = this;
                                if (!context) {
                                    return;
                                }
                                classCarierBkp = context.__classCarier__;
                                methodClassCarierBkp = context.__methodClassCarier__;
                                origPropBkp = context.__origProp__;

                                context.__methodClassCarier__ = instance;

                                context.__classCarier__ = null;

                                context.__origProp__ = finalMethodName;
                                returnValue = prototypes[originalMethodName].apply(context, arguments);
                                context.__origProp__ = origPropBkp;

                                context.__classCarier__ = classCarierBkp;

                                context.__methodClassCarier__ = methodClassCarierBkp;

                                return returnValue;

                            };
                        })(name, finalName);
                    }
                    Object.defineProperty(proto, finalName, propDescriptor);
                }
            }
            else {
                extraInfo = '';
                nameInProto && (extraInfo = 'property is already available (you might force it to be set)');
                PROTO_RESERVED_NAMES[finalName] && (extraInfo = 'property is a protected property');
                protectedMap[finalName] && (extraInfo = 'property is a private property');
                console.warn(NAME+'mergePrototypes is not allowed to set the property: '+name+' --> '+extraInfo);
            }
        }
        return instance;
    }
function (prototypes, force) {
        var instance, proto, names, l, i, replaceMap, protectedMap, name, nameInProto, finalName, propDescriptor, extraInfo;
        if (!prototypes) {
            return;
        }
        instance = this; // the Class
        proto = instance.prototype;
        names = Object.getOwnPropertyNames(prototypes);
        l = names.length;
        i = -1;
        replaceMap = arguments[2] || REPLACE_CLASS_METHODS; // hidden feature, used by itags

        protectedMap = arguments[3] || PROTECTED_CLASS_METHODS; // hidden feature, used by itags
        while (++i < l) {
            name = names[i];
            finalName = replaceMap[name] || name;
            nameInProto = (finalName in proto);
            if (!PROTO_RESERVED_NAMES[finalName] && !protectedMap[finalName] && (!nameInProto || force)) {
                // if nameInProto: set the property, but also backup for chaining using $$orig
                propDescriptor = Object.getOwnPropertyDescriptor(prototypes, name);
                if (!propDescriptor.writable) {
                    console.info(NAME+'mergePrototypes will set property of '+name+' without its property-descriptor: for it is an unwritable property.');
                    proto[finalName] = prototypes[name];
                }
                else {
                    // adding prototypes[name] into $$orig:
                    instance.$$orig[finalName] || (instance.$$orig[finalName]=[]);
                    instance.$$orig[finalName][instance.$$orig[finalName].length] = prototypes[name];
                    if (typeof prototypes[name] === 'function') {
    /*jshint -W083 */
                        propDescriptor.value = (function (originalMethodName, finalMethodName) {
                            return function () {
    /*jshint +W083 */
                                // this.$own = prot;
                                // this.$origMethods = instance.$$orig[finalMethodName];
                                var context, classCarierBkp, methodClassCarierBkp, origPropBkp, returnValue;
                                // in some specific situations, this method is called without context.
                                // can't figure out why (it happens when itable changes some of its its item-values)
                                // probably reasson is that itable.model.items is not the same as itable.getData('_items')
                                // anyway: to prevent errors here, we must return when there is no context:
                                context = this;
                                if (!context) {
                                    return;
                                }
                                classCarierBkp = context.__classCarier__;
                                methodClassCarierBkp = context.__methodClassCarier__;
                                origPropBkp = context.__origProp__;

                                context.__methodClassCarier__ = instance;

                                context.__classCarier__ = null;

                                context.__origProp__ = finalMethodName;
                                returnValue = prototypes[originalMethodName].apply(context, arguments);
                                context.__origProp__ = origPropBkp;

                                context.__classCarier__ = classCarierBkp;

                                context.__methodClassCarier__ = methodClassCarierBkp;

                                return returnValue;

                            };
                        })(name, finalName);
                    }
                    Object.defineProperty(proto, finalName, propDescriptor);
                }
            }
            else {
                extraInfo = '';
                nameInProto && (extraInfo = 'property is already available (you might force it to be set)');
                PROTO_RESERVED_NAMES[finalName] && (extraInfo = 'property is a protected property');
                protectedMap[finalName] && (extraInfo = 'property is a private property');
                console.warn(NAME+'mergePrototypes is not allowed to set the property: '+name+' --> '+extraInfo);
            }
        }
        return instance;
    }
function ( prototypes , force ) { var instance , proto , names , l , i , replaceMap , protectedMap , name , nameInProto , finalName , propDescriptor , extraInfo ; if ( ! prototypes ) { return ; } instance = this ; // the Class proto = instance . prototype ; names = Object . getOwnPropertyNames ( prototypes ) ; l = names . length ; i = - 1 ; replaceMap = arguments [ 2 ] || REPLACE_CLASS_METHODS ; // hidden feature, used by itags protectedMap = arguments [ 3 ] || PROTECTED_CLASS_METHODS ; // hidden feature, used by itags while ( ++ i < l ) { name = names [ i ] ; finalName = replaceMap [ name ] || name ; nameInProto = ( finalName in proto ) ; if ( ! PROTO_RESERVED_NAMES [ finalName ] && ! protectedMap [ finalName ] && ( ! nameInProto || force ) ) { // if nameInProto: set the property, but also backup for chaining using $$orig propDescriptor = Object . getOwnPropertyDescriptor ( prototypes , name ) ; if ( ! propDescriptor . writable ) { console . info ( NAME + 'mergePrototypes will set property of ' + name + ' without its property-descriptor: for it is an unwritable property.' ) ; proto [ finalName ] = prototypes [ name ] ; } else { // adding prototypes[name] into $$orig: instance . $$orig [ finalName ] || ( instance . $$orig [ finalName ] = [ ] ) ; instance . $$orig [ finalName ] [ instance . $$orig [ finalName ] . length ] = prototypes [ name ] ; if ( typeof prototypes [ name ] === 'function' ) { /*jshint -W083 */ propDescriptor . value = ( function ( originalMethodName , finalMethodName ) { return function ( ) { /*jshint +W083 */ // this.$own = prot; // this.$origMethods = instance.$$orig[finalMethodName]; var context , classCarierBkp , methodClassCarierBkp , origPropBkp , returnValue ; // in some specific situations, this method is called without context. // can't figure out why (it happens when itable changes some of its its item-values) // probably reasson is that itable.model.items is not the same as itable.getData('_items') // anyway: to prevent errors here, we must return when there is no context: context = this ; if ( ! context ) { return ; } classCarierBkp = context . __classCarier__ ; methodClassCarierBkp = context . __methodClassCarier__ ; origPropBkp = context . __origProp__ ; context . __methodClassCarier__ = instance ; context . __classCarier__ = null ; context . __origProp__ = finalMethodName ; returnValue = prototypes [ originalMethodName ] . apply ( context , arguments ) ; context . __origProp__ = origPropBkp ; context . __classCarier__ = classCarierBkp ; context . __methodClassCarier__ = methodClassCarierBkp ; return returnValue ; } ; } ) ( name , finalName ) ; } Object . defineProperty ( proto , finalName , propDescriptor ) ; } } else { extraInfo = '' ; nameInProto && ( extraInfo = 'property is already available (you might force it to be set)' ) ; PROTO_RESERVED_NAMES [ finalName ] && ( extraInfo = 'property is a protected property' ) ; protectedMap [ finalName ] && ( extraInfo = 'property is a private property' ) ; console . warn ( NAME + 'mergePrototypes is not allowed to set the property: ' + name + ' --> ' + extraInfo ) ; } } return instance ; }
Merges the given prototypes of properties into the `prototype` of the Class.

**Note1 ** to be used on instances --> ONLY on Classes
**Note2 ** properties with getters and/or unwritable will NOT be merged

The members in the hash prototypes will become members with
instances of the merged class.

By default, this method will not override existing prototype members,
unless the second argument `force` is true.

@method mergePrototypes
@param prototypes {Object} Hash prototypes of properties to add to the prototype of this object
@param force {Boolean}  If true, existing members will be overwritten
@chainable
Merges the given prototypes of properties into the prototype of the Class .