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;
}
文档是有点简单了,看一下代码才知道怎么回事