From 2bc25644fd89a9c490330500da0d7ee3099d6494 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sun, 17 Apr 2016 14:22:35 +0800 Subject: [PATCH] small optimization --- cocos2d/core/value-types/CCColor.js | 6 +++--- cocos2d/core/value-types/CCRect.js | 8 ++++---- cocos2d/core/value-types/CCSize.js | 4 ++-- cocos2d/core/value-types/CCVec2.js | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cocos2d/core/value-types/CCColor.js b/cocos2d/core/value-types/CCColor.js index 2df8f5d586..3bbdda10f0 100644 --- a/cocos2d/core/value-types/CCColor.js +++ b/cocos2d/core/value-types/CCColor.js @@ -61,9 +61,9 @@ var Color = (function () { a = r.a; r = r.r; } - this.r = typeof r === 'number' ? r : 0; - this.g = typeof g === 'number' ? g : 0; - this.b = typeof b === 'number' ? b : 0; + this.r = r || 0; + this.g = g || 0; + this.b = b || 0; this.a = typeof a === 'number' ? a : 255; } JS.extend(Color, ValueType); diff --git a/cocos2d/core/value-types/CCRect.js b/cocos2d/core/value-types/CCRect.js index 82da656629..d163fb91d6 100644 --- a/cocos2d/core/value-types/CCRect.js +++ b/cocos2d/core/value-types/CCRect.js @@ -53,10 +53,10 @@ function Rect (x, y, w, h) { h = x.height; x = x.x; } - this.x = typeof x === 'number' ? x : 0.0; - this.y = typeof y === 'number' ? y : 0.0; - this.width = typeof w === 'number' ? w : 0.0; - this.height = typeof h === 'number' ? h : 0.0; + this.x = x || 0; + this.y = y || 0; + this.width = w || 0; + this.height = h || 0; } JS.extend(Rect, ValueType); require('../platform/CCClass').fastDefine('cc.Rect', Rect, ['x', 'y', 'width', 'height']); diff --git a/cocos2d/core/value-types/CCSize.js b/cocos2d/core/value-types/CCSize.js index a16e12b4ab..c15532fc55 100644 --- a/cocos2d/core/value-types/CCSize.js +++ b/cocos2d/core/value-types/CCSize.js @@ -52,8 +52,8 @@ function Size (width, height) { height = width.height; width = width.width; } - this.width = typeof width === 'number' ? width : 0; - this.height = typeof height === 'number' ? height : 0; + this.width = width || 0; + this.height = height || 0; } JS.extend(Size, ValueType); require('../platform/CCClass').fastDefine('cc.Size', Size, ['width', 'height']); diff --git a/cocos2d/core/value-types/CCVec2.js b/cocos2d/core/value-types/CCVec2.js index 4565714724..6119a67d19 100644 --- a/cocos2d/core/value-types/CCVec2.js +++ b/cocos2d/core/value-types/CCVec2.js @@ -52,8 +52,8 @@ function Vec2 (x, y) { y = x.y; x = x.x; } - this.x = (typeof x === 'number' ? x : 0.0); - this.y = (typeof y === 'number' ? y : 0.0); + this.x = x || 0; + this.y = y || 0; } JS.extend(Vec2, ValueType); FireClass.fastDefine('cc.Vec2', Vec2, ['x', 'y']);