KISSYのKISSY.JS速記


もっと読む
https://github.com/kissyteam/kissy/blob/1.1.6/src/seed/kissy.js

(function(S, undef) {
    var meta = {
          /**
           * copy s r,  over, s[p] overwrite r[p], 
           *    whitelist,   s copy whitelist    p
           * @return r
           */
          mix: function(reciveObj, sourceObj, over, whitelist) {
                     ...}
    }
    host = this,

    seed = host[S] || {},

    guid = 0,
    EMPTY = '';

    if(!seed.mix) seed.mix = meta.mix;
    S = host[S] = seed; // shortcut

    S.mix(S, {

         // The host of runtime environment.
        __HOST: host,

        // S.app() with these members.
        __APP_MEMBERS: ['namespace'],
        __APP_INIT_METHODS: ['__init'],

        version: '@VERSION@',

        /**
         *   mix o1、o2 on,mix     overwrite
         */
        merge: function(/*o1,o2...on*/) {
            var o = {}, i, l = arguments.length;
            for (i = 0; i < l; ++i) {
                S.mix(o, arguments[i]);
            }
            return o;
        },

        /**
         * mix copy  s[p] r[p], augment copy s.prototype[p] r.prototype[p]
         *   s  prototype  , copy s[p]
         */
        augment: function(/*receiveObj, srcObj1, srcObj2, ..., over, whitelist*/) {
                            ...},
        /**
         * r extend s, r.prototype overwrite mix px, r overwrite mix sx
         * r.superclass = s.protype
         */
        extend: function(r, s, px, sx) {
            if (!s || !r) return r;

            var OP = Object.prototype,
                O = function (o) {
                    function F() {
                    }

                    F.prototype = o;
                    return new F();
                },
                sp = s.prototype,
                rp = O(sp);

            r.prototype = rp;
            rp.constructor = r;
            r.superclass = sp;

            // assign constructor property
            if (s !== Object && sp.constructor === OP.constructor) {
                sp.constructor = s;
            }

            // add prototype overrides
            if (px) {
                S.mix(rp, px);
            }

            // add object overrides
            if (sx) {
                S.mix(r, sx);
            }

            return r;
        },
        __init: function() {
            this.Config = this.Config || {};
            this.Env = this.Env || {};
            this.Config.debug = '@DEBUG@';
        },
        namespace: function() { ...},
        /**
         *      o(host[name]   name  )  APP  ,
         *   KISSY mix KISSY.__APP_MEMBERS,
         *      o   KISSY.__APP_INIT_METHODS
         *   mix sx()        sx  
         * @param {String|Object}  name
         * @param {Function|Object} sx
         */
        app: function(name, sx) {
            var isStr = S.isString(name),
                O = isStr ? host[name] || {} : name,
                i = 0,
                len = S.__APP_INIT_METHODS.length;

            S.mix(O, this, true, S.__APP_MEMBERS);
            for(; i < len; ++i) S[S.__APP_INIT_METHODS[i]].call(O);

            S.mix(O, S.isFunction(sx) ? sx() : sx);
            isStr && (host[name] = O);

            return O;
        },
        log: function(msg, cat, src) { ...},
        error: function(msg) {...},
        guid: function(pre) { return (pre || EMPTY) + guid++;  }
     });
   S.__init();
})('KISSY');