Quantcast
Channel: Cocos中文社区 - 最新帖子
Viewing all articles
Browse latest Browse all 494966

Cc.js.extend怎么用,没有相关文档

$
0
0

API文档:http://cocos.com/docs/creator/api/modules/js.html#method_extend
函数代码:

    /**
     * Derive the class from the supplied base class.
     * Both classes are just native javascript constructors, not created by cc.Class, so
     * usually you will want to inherit using {{#crossLink "cc/Class:method"}}cc.Class {{/crossLink}} instead.
     *
     * @method extend
     * @param {Function} cls
     * @param {Function} base - the baseclass to inherit
     * @return {Function} the result class
     */
    extend: function (cls, base) {
        if (CC_DEV) {
            if (!base) {
                cc.error('The base class to extend from must be non-nil');
                return;
            }
            if (!cls) {
                cc.error('The class to extend must be non-nil');
                return;
            }
            if (Object.keys(cls.prototype).length > 0) {
                cc.error('Class should be extended before assigning any prototype members.');
            }
        }
        for (var p in base) if (base.hasOwnProperty(p)) cls[p] = base[p];
        cls.prototype = Object.create(base.prototype);
        cls.prototype.constructor = cls;
        return cls;
    }

文档是有点简单了,看一下代码才知道怎么回事


Viewing all articles
Browse latest Browse all 494966

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>