From fa44c6bc00a2b722be07428437b90098e19cc453 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 14 Apr 2017 16:15:32 +0800 Subject: [PATCH 1/3] minor tweaks --- cocos2d/core/platform/CCClass.js | 32 ++++++++++++++----------------- cocos2d/core/platform/_CCClass.js | 24 +++++++++++------------ test/qunit/unit/test-class.js | 2 +- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index c2c4453544..d2ab536ad3 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -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 Date: Mon, 17 Apr 2017 10:38:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20global=20variable=20=E2=80=98j?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/event/event-target.js | 2 +- cocos2d/tilemap/CCTMXXMLParser.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index a122793eab..3ac3a0b50b 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -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. diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index efe3f565ab..fe7281934a 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -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 From 05c8871b5c0663a355dce742eb5ac31af88c4d2e Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 17 Apr 2017 13:54:48 +0800 Subject: [PATCH 3/3] fix test loadResDir --- test/qunit/unit-es5/test-resources-loader.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/qunit/unit-es5/test-resources-loader.js b/test/qunit/unit-es5/test-resources-loader.js index 378e292e2c..c998af6842 100644 --- a/test/qunit/unit-es5/test-resources-loader.js +++ b/test/qunit/unit-es5/test-resources-loader.js @@ -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(); }); });