mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
@@ -138,7 +138,7 @@ JS.mixin(EventTarget.prototype, {
|
||||
|
||||
/**
|
||||
* !#en Checks whether the EventTarget object has any callback registered for a specific type of event.
|
||||
* !#zh 检查事件目标对象是否为不特定类型的事件注册的回调。
|
||||
* !#zh 检查事件目标对象是否有为特定类型的事件注册的回调。
|
||||
* @param {String} type - The type of event.
|
||||
* @param {Boolean} checkCapture - Check for capturing or bubbling phase, check bubbling phase by default.
|
||||
* @return {Boolean} True if a callback of the specified type is registered in specified phase; false otherwise.
|
||||
|
||||
@@ -343,20 +343,22 @@ function doDefine (className, baseClass, mixins, options) {
|
||||
});
|
||||
|
||||
|
||||
var prototype = fireClass.prototype;
|
||||
if (baseClass) {
|
||||
if (!__es6__) {
|
||||
JS.extend(fireClass, baseClass); // 这里会把父类的 __props__ 复制给子类
|
||||
prototype = fireClass.prototype; // get extended prototype
|
||||
}
|
||||
fireClass.$super = baseClass;
|
||||
if (CC_DEV && shouldAddProtoCtor) {
|
||||
fireClass.prototype.ctor = function () {};
|
||||
prototype.ctor = function () {};
|
||||
}
|
||||
}
|
||||
|
||||
if (mixins) {
|
||||
for (var m = mixins.length - 1; m >= 0; m--) {
|
||||
var mixin = mixins[m];
|
||||
mixinWithInherited(fireClass.prototype, mixin.prototype);
|
||||
mixinWithInherited(prototype, mixin.prototype);
|
||||
|
||||
// mixin statics (this will also copy editor attributes for component)
|
||||
mixinWithInherited(fireClass, mixin, function (prop) {
|
||||
@@ -372,11 +374,11 @@ function doDefine (className, baseClass, mixins, options) {
|
||||
}
|
||||
}
|
||||
// restore constuctor overridden by mixin
|
||||
fireClass.prototype.constructor = fireClass;
|
||||
prototype.constructor = fireClass;
|
||||
}
|
||||
|
||||
if (!__es6__) {
|
||||
fireClass.prototype.__initProps__ = compileProps;
|
||||
prototype.__initProps__ = compileProps;
|
||||
}
|
||||
|
||||
JS.setClassName(className, fireClass);
|
||||
@@ -562,9 +564,9 @@ function compileProps (actualClass) {
|
||||
}
|
||||
|
||||
function _createCtor (ctors, baseClass, className, options) {
|
||||
// bound super calls
|
||||
var superCallBounded = baseClass && boundSuperCalls(baseClass, options, className);
|
||||
|
||||
// create class constructor
|
||||
var body;
|
||||
var args = CC_JSB ? '...args' : '';
|
||||
if (CC_DEV) {
|
||||
@@ -582,26 +584,20 @@ function _createCtor (ctors, baseClass, className, options) {
|
||||
body += 'this.__initProps__(fireClass);\n';
|
||||
|
||||
// call user constructors
|
||||
if (ctors.length > 0) {
|
||||
var ctorLen = ctors.length;
|
||||
if (ctorLen > 0) {
|
||||
var useTryCatch = ! (className && className.startsWith('cc.'));
|
||||
if (useTryCatch) {
|
||||
body += 'try{\n';
|
||||
}
|
||||
var SNIPPET = CC_JSB ? ']).apply(this,args);\n' : ']).apply(this,arguments);\n';
|
||||
if (ctors.length === 1) {
|
||||
body += '(fireClass.__ctors__[0' + SNIPPET;
|
||||
var SNIPPET = CC_JSB ? '].apply(this,args);\n' : '].apply(this,arguments);\n';
|
||||
if (ctorLen === 1) {
|
||||
body += 'fireClass.__ctors__[0' + SNIPPET;
|
||||
}
|
||||
else {
|
||||
body += 'var cs=fireClass.__ctors__;\n';
|
||||
if (ctors.length <= 5) {
|
||||
for (var i = 0; i < ctors.length; i++) {
|
||||
body += '(cs[' + i + SNIPPET;
|
||||
}
|
||||
}
|
||||
else {
|
||||
body += 'for(var i=0,l=cs.length;i<l;++i){\n' +
|
||||
'(cs[i' + SNIPPET +
|
||||
'}\n';
|
||||
for (var i = 0; i < ctorLen; i++) {
|
||||
body += 'cs[' + i + SNIPPET;
|
||||
}
|
||||
}
|
||||
if (useTryCatch) {
|
||||
|
||||
@@ -79,18 +79,18 @@ Class.extend = function (props) {
|
||||
if (cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) {
|
||||
var ctor =
|
||||
"return (function " + (props._className || "Class") + "(arg0,arg1,arg2,arg3,arg4) {\n" +
|
||||
"this.__instanceId = cc.ClassManager.getNewInstanceId();\n" +
|
||||
"if (this.ctor) {\n" +
|
||||
"switch (arguments.length) {\n" +
|
||||
"case 0: this.ctor(); break;\n" +
|
||||
"case 1: this.ctor(arg0); break;\n" +
|
||||
"case 2: this.ctor(arg0,arg1); break;\n" +
|
||||
"case 3: this.ctor(arg0,arg1,arg2); break;\n" +
|
||||
"case 4: this.ctor(arg0,arg1,arg2,arg3); break;\n" +
|
||||
"case 5: this.ctor(arg0,arg1,arg2,arg3,arg4); break;\n" +
|
||||
"default: this.ctor.apply(this, arguments);\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"this.__instanceId = cc.ClassManager.getNewInstanceId();\n" +
|
||||
"if (this.ctor) {\n" +
|
||||
"switch (arguments.length) {\n" +
|
||||
"case 0: this.ctor(); break;\n" +
|
||||
"case 1: this.ctor(arg0); break;\n" +
|
||||
"case 2: this.ctor(arg0,arg1); break;\n" +
|
||||
"case 3: this.ctor(arg0,arg1,arg2); break;\n" +
|
||||
"case 4: this.ctor(arg0,arg1,arg2,arg3); break;\n" +
|
||||
"case 5: this.ctor(arg0,arg1,arg2,arg3,arg4); break;\n" +
|
||||
"default: this.ctor.apply(this, arguments);\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"});";
|
||||
TheClass = Function(ctor)();
|
||||
}
|
||||
|
||||
@@ -848,7 +848,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
var objects = selGroup.querySelectorAll('object');
|
||||
var getContentScaleFactor = cc.director.getContentScaleFactor();
|
||||
if (objects) {
|
||||
for (j = 0; j < objects.length; j++) {
|
||||
for (var j = 0; j < objects.length; j++) {
|
||||
var selObj = objects[j];
|
||||
// The value for "type" was blank or not a valid class name
|
||||
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||
|
||||
@@ -100,13 +100,12 @@
|
||||
});
|
||||
|
||||
asyncTest('url dict of loadResDir', function () {
|
||||
cc.loader.loadResDir('', cc.Texture2D, function (err, results, urlToRes) {
|
||||
var urls = Object.keys(urlToRes);
|
||||
cc.loader.loadResDir('', cc.Texture2D, function (err, results, urls) {
|
||||
strictEqual(results.length, urls.length, 'url dict should contains the same count with array');
|
||||
|
||||
var url = urls[0];
|
||||
cc.loader.loadRes(url, cc.Texture2D, function (err, result) {
|
||||
strictEqual(result, urlToRes[url], 'url is correct');
|
||||
strictEqual(result, results[0], 'url is correct');
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -665,7 +665,7 @@ largeModule('Class ES6');
|
||||
class BigDog extends Dog {
|
||||
constructor () {
|
||||
super();
|
||||
Mixin.call(this);
|
||||
Mixin.call(this); // expect Mixin will call its own ctor rather than this's
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user