diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 147c2f80fe..e36d7f0d4c 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1521,7 +1521,7 @@ var Node = cc.Class({ */ setPosition (newPosOrX, y) { var x; - if (typeof y === 'undefined') { + if (y === undefined) { x = newPosOrX.x; y = newPosOrX.y; } @@ -1592,7 +1592,7 @@ var Node = cc.Class({ * node.setScale(1, 1); */ setScale (scaleX, scaleY) { - if (typeof scaleX === 'object') { + if (scaleY === undefined) { scaleY = scaleX.y; scaleX = scaleX.x; } diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index 75934a501d..765bf9084a 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -239,7 +239,7 @@ proto.hasEventListener = function (type, checkCapture) { */ proto.on = function (type, callback, target, useCapture) { // Accept also patameters like: (type, callback, useCapture) - if (typeof target === 'boolean') { + if (useCapture === undefined) { useCapture = target; target = undefined; } @@ -296,7 +296,7 @@ proto.on = function (type, callback, target, useCapture) { */ proto.off = function (type, callback, target, useCapture) { // Accept also patameters like: (type, callback, useCapture) - if (typeof target === 'boolean') { + if (useCapture === undefined) { useCapture = target; target = undefined; } diff --git a/cocos2d/core/node-activator.js b/cocos2d/core/node-activator.js index 9f6cc82c48..b91a806fe8 100644 --- a/cocos2d/core/node-activator.js +++ b/cocos2d/core/node-activator.js @@ -250,7 +250,7 @@ var NodeActivator = cc.Class({ if (cc.engine._isPlaying || comp.constructor._executeInEditMode) { if (!(comp._objFlags & IsPreloadStarted)) { comp._objFlags |= IsPreloadStarted; - if (typeof comp.__preload === 'function') { + if (comp.__preload) { if (preloadInvoker) { preloadInvoker.add(comp); } @@ -285,7 +285,7 @@ var NodeActivator = cc.Class({ } : function (comp, preloadInvoker, onLoadInvoker, onEnableInvoker) { if (!(comp._objFlags & IsPreloadStarted)) { comp._objFlags |= IsPreloadStarted; - if (typeof comp.__preload === 'function') { + if (comp.__preload) { if (preloadInvoker) { preloadInvoker.add(comp); } @@ -337,7 +337,7 @@ var NodeActivator = cc.Class({ }, resetComp: CC_EDITOR && function (comp) { - if (typeof comp.resetInEditor === 'function') { + if (comp.resetInEditor) { callResetInTryCatch(comp); } } diff --git a/cocos2d/core/platform/CCInputManager.js b/cocos2d/core/platform/CCInputManager.js index ac322a4afa..28d8963eb7 100644 --- a/cocos2d/core/platform/CCInputManager.js +++ b/cocos2d/core/platform/CCInputManager.js @@ -232,7 +232,7 @@ var inputManager = { var docElem = document.documentElement; var leftOffset = window.pageXOffset - docElem.clientLeft; var topOffset = window.pageYOffset - docElem.clientTop; - if (typeof element.getBoundingClientRect === 'function') { + if (element.getBoundingClientRect) { var box = element.getBoundingClientRect(); return { left: box.left + leftOffset, diff --git a/cocos2d/core/platform/CCScreen.js b/cocos2d/core/platform/CCScreen.js index 0a440f4d88..c6121bc5a9 100644 --- a/cocos2d/core/platform/CCScreen.js +++ b/cocos2d/core/platform/CCScreen.js @@ -92,7 +92,7 @@ cc.screen = /** @lends cc.screen# */{ } } - this._supportsFullScreen = (typeof this._fn.requestFullscreen !== 'undefined'); + this._supportsFullScreen = (this._fn.requestFullscreen !== undefined); this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown'; }, diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index ecceabc55f..4959be674e 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -296,7 +296,7 @@ var _Deserializer = (function () { // 和 _deserializeObject 不同的地方在于会判断 id 和 uuid prototype._deserializeObjField = function (obj, jsonObj, propName, target, _stillUseUrl) { var id = jsonObj.__id__; - if (typeof id === 'undefined') { + if (id === undefined) { var uuid = jsonObj.__uuid__; if (uuid) { //if (ENABLE_TARGET) { @@ -413,7 +413,7 @@ var _Deserializer = (function () { for (var i = 0; i < fastDefinedProps.length; i++) { var propName = fastDefinedProps[i]; var prop = serialized[propName]; - if (typeof prop !== 'undefined' && serialized.hasOwnProperty(propName)) { + if (prop !== undefined && serialized.hasOwnProperty(propName)) { if (typeof prop !== 'object') { instance[propName] = prop; } @@ -612,7 +612,7 @@ var _Deserializer = (function () { prop = d[propNameToRead]; - if (typeof prop !== 'undefined') { + if (prop !== undefined) { var stillUseUrl = attrs[propName + SAVE_URL_AS_ASSET]; // function undefined object(null) string boolean number var defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]); diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index 2862913ec7..a1323e274c 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -269,11 +269,11 @@ var tmpGetSetDesc = { * @param {Object} obj * @param {String} prop * @param {Function} getter - * @param {Function} setter + * @param {Function} [setter=null] * @param {Boolean} [enumerable=false] */ js.getset = function (obj, prop, getter, setter, enumerable) { - if (typeof setter !== 'function') { + if (enumerable === undefined) { enumerable = setter; setter = undefined; } @@ -897,7 +897,7 @@ js.array = { * constructor(size: number) */ function Pool (cleanupFunc, size) { - if (typeof cleanupFunc === 'number') { + if (size === undefined) { size = cleanupFunc; cleanupFunc = null; } diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 97f6762cc0..503e290ce2 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -311,7 +311,7 @@ var BaseNode = cc.Class({ * @param {String} [name] */ ctor (name) { - this._name = typeof name !== 'undefined' ? name : 'New Node'; + this._name = name !== undefined ? name : 'New Node'; this._activeInHierarchy = false; // Support for ActionManager and EventManager