Merge pull request #2543 from pandamicro/optimize

Remove useless typeof check
This commit is contained in:
pandamicro
2018-04-16 16:34:25 +08:00
committed by GitHub
8 changed files with 16 additions and 16 deletions
+2 -2
View File
@@ -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;
}
+2 -2
View File
@@ -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;
}
+3 -3
View File
@@ -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);
}
}
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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';
},
+3 -3
View File
@@ -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]);
+3 -3
View File
@@ -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;
}
+1 -1
View File
@@ -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