diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index e20f9d6694..705f1cef2d 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -24,7 +24,6 @@ 'use strict'; -var EventTarget = require('./event/event-target'); var PrefabHelper = require('./utils/prefab-helper'); var JS = cc.js; @@ -327,7 +326,6 @@ function findChildComponents (children, constructor, components) { var Node = cc.Class({ name: 'cc.Node', extends: require('./utils/base-node'), - mixins: [EventTarget], properties: { /** diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index d30e79ab80..7eb97ce0e2 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -542,11 +542,17 @@ function _createCtor (ctor, baseClass, mixins, className, options) { if (CCClass._isCCClass(baseOrMixin)) { var baseCtors = baseOrMixin.__ctors__; if (baseCtors) { - ctors = ctors.concat(baseCtors); + for (var c = 0; c < baseCtors.length; c++) { + if (ctors.indexOf(baseCtors[c]) < 0) { + ctors.push(baseCtors[c]); + } + } } } else if (baseOrMixin) { - ctors.push(baseOrMixin); + if (ctors.indexOf(baseOrMixin) < 0) { + ctors.push(baseOrMixin); + } } } } diff --git a/test/qunit/unit/test-class.js b/test/qunit/unit/test-class.js index 7c3086db86..649c2dbcb8 100644 --- a/test/qunit/unit/test-class.js +++ b/test/qunit/unit/test-class.js @@ -280,7 +280,7 @@ test('prop initial times', function () { configurable: true }); Base.call(instanceMocker); - fooTester.once('property should init once'); + fooTester.once('property should init only once'); var Sub = cc.Class({ extends: Base, @@ -591,6 +591,26 @@ test('mixins', function () { strictEqual(cc.Class.attr(BigDog, 'p1').default, 'Defined by BigDog', "should override base property"); }); +test('mixins ctor', function () { + var ctorOfMixin = Callback().enable(); + + var Mixin = cc.Class({ + ctor: function () { + ctorOfMixin(); + }, + }); + var Dog = cc.Class({ + mixins: [Mixin], + }); + var BigDog = cc.Class({ + extends: Dog, + mixins: [Mixin], + }); + + new BigDog(); + ctorOfMixin.once('ctor of mixin should be called only once'); +}); + asyncTest('instantiate properties in the next frame', function () { var Dog = cc.Class({ properties: function () {