diff --git a/cocos2d/core/platform/instantiate-jit.js b/cocos2d/core/platform/instantiate-jit.js index a1f0665c0b..f5a19bc8b9 100644 --- a/cocos2d/core/platform/instantiate-jit.js +++ b/cocos2d/core/platform/instantiate-jit.js @@ -324,7 +324,7 @@ proto.enumerateCCClass = function (codeArray, obj, klass) { } if (typeof val === 'object' && val instanceof cc.ValueType) { var defaultValue = CCClass.getDefault(defaultValue); - if (defaultValue.constructor === val.constructor) { + if ((defaultValue && defaultValue.constructor) === val.constructor) { // fast case var targetExpression = LOCAL_OBJ + getPropAccessor(key); this.setValueType(codeArray, defaultValue, val, targetExpression); diff --git a/test/qunit/unit-es5/test-instantiate.js b/test/qunit/unit-es5/test-instantiate.js index 8863ababaa..018e622c29 100644 --- a/test/qunit/unit-es5/test-instantiate.js +++ b/test/qunit/unit-es5/test-instantiate.js @@ -262,6 +262,23 @@ function testInstantiate (module, match, instantiate) { cc.js.unregisterClass(Script); }); + + test('will not throw error if type is wrong', function () { + var Type = cc.Class({ + properties: { + value: { + default: null + } + } + }); + + var obj = new Type(); + obj.value = cc.Vec2.ONE; + + var cloned = instantiate(obj); + + ok(cloned.value.equals(obj.value), 'same value'); + }); } testInstantiate('Instantiate', function (obj, expect, info) {