Skip to content

Commit a851c87

Browse files
committed
Refactor #3985: arguments length check replaced by undefined check in extension
1 parent 2840cf0 commit a851c87

File tree

13 files changed

+76
-81
lines changed

13 files changed

+76
-81
lines changed

extensions/CocoStudio/Armature/display/CCDisplayManager.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ ccs.DisplayManager = ccs.Class.extend({
252252
}
253253
},
254254

255-
containPoint:function (/*point|x,y*/) {
255+
containPoint: function (point, y) {
256256
var p = cc.p(0, 0);
257-
if (arguments.length == 1) {
258-
p.x = arguments[0].x;
259-
p.y = arguments[0].y;
260-
} else if (arguments.length == 2) {
261-
p.x = arguments[0];
262-
p.y = arguments[1];
257+
if (y === undefined) {
258+
p.x = point.x;
259+
p.y = point.y;
260+
} else {
261+
p.x = point;
262+
p.y = y;
263263
}
264264
if (!this._visible || this._displayIndex < 0) {
265265
return false;

extensions/CocoStudio/Armature/utils/CCArmatureDataManager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ ccs.ArmatureDataManager = ccs.Class.extend(/** @lends ccs.ArmatureDataManager# *
221221
* //example2
222222
* ccs.ArmatureDataManager.getInstance().addArmatureFileInfo("res/test.png","res/test.plist","res/test.json");
223223
*/
224-
addArmatureFileInfo:function (/*imagePath,plistPath,configFilePath*/) {
225-
var imagePath,plistPath,configFilePath;
224+
addArmatureFileInfo:function (/*imagePath, plistPath, configFilePath*/) {
225+
var imagePath, plistPath, configFilePath;
226226
var isLoadSpriteFrame = false;
227227
if (arguments.length == 1) {
228228
configFilePath = arguments[0];
@@ -246,8 +246,8 @@ ccs.ArmatureDataManager = ccs.Class.extend(/** @lends ccs.ArmatureDataManager# *
246246
* @param {Object} target
247247
* @param {Function} configFilePath
248248
*/
249-
addArmatureFileInfoAsync:function (/*imagePath, plistPath, configFilePath,target,selector*/) {
250-
var imagePath, plistPath, configFilePath,target,selector;
249+
addArmatureFileInfoAsync:function (/*imagePath, plistPath, configFilePath, target, selector*/) {
250+
var imagePath, plistPath, configFilePath, target, selector;
251251
var isLoadSpriteFrame = false;
252252
if (arguments.length == 3) {
253253
configFilePath = arguments[0];

extensions/CocoStudio/GUI/Layouts/UILayoutDefine.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,18 @@ ccs.Margin = ccs.Class.extend(/** @lends ccs.Margin# */{
7575
top: 0,
7676
right: 0,
7777
bottom: 0,
78-
ctor: function () {
79-
if (arguments.length == 1) {
80-
var uiMargin = arguments[0];
81-
this.left = uiMargin.left;
82-
this.top = uiMargin.top;
83-
this.right = uiMargin.right;
84-
this.bottom = uiMargin.bottom;
78+
ctor: function (margin, top, right, bottom) {
79+
if (top === undefined) {
80+
this.left = margin.left;
81+
this.top = margin.top;
82+
this.right = margin.right;
83+
this.bottom = margin.bottom;
8584
}
86-
if (arguments.length == 4) {
87-
this.left = arguments[0];
88-
this.top = arguments[1];
89-
this.right = arguments[2];
90-
this.bottom = arguments[3];
85+
if (bottom !== undefined) {
86+
this.left = margin;
87+
this.top = top;
88+
this.right = right;
89+
this.bottom = bottom;
9190
}
9291
},
9392
/**

extensions/CocoStudio/GUI/UIWidgets/UIButton.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,18 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
485485
* @param {Number} [y] The anchor point.y of UIButton.
486486
*/
487487
setAnchorPoint: function (point, y) {
488-
if(arguments.length === 2){
489-
ccs.Widget.prototype.setAnchorPoint.call(this,point, y);
490-
this._buttonNormalRenderer.setAnchorPoint(point, y);
491-
this._buttonClickedRenderer.setAnchorPoint(point, y);
492-
this._buttonDisableRenderer.setAnchorPoint(point, y);
493-
this._titleRenderer.setPosition(this._size.width * (0.5 - this._anchorPoint._x), this._size.height * (0.5 - this._anchorPoint._y));
488+
if(y === undefined){
489+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
490+
this._buttonNormalRenderer.setAnchorPoint(point);
491+
this._buttonClickedRenderer.setAnchorPoint(point);
492+
this._buttonDisableRenderer.setAnchorPoint(point);
494493
} else {
495-
ccs.Widget.prototype.setAnchorPoint.call(this,point);
496-
this._buttonNormalRenderer.setAnchorPoint(point);
497-
this._buttonClickedRenderer.setAnchorPoint(point);
498-
this._buttonDisableRenderer.setAnchorPoint(point);
499-
this._titleRenderer.setPosition(this._size.width * (0.5 - this._anchorPoint._x), this._size.height * (0.5 - this._anchorPoint._y));
494+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
495+
this._buttonNormalRenderer.setAnchorPoint(point, y);
496+
this._buttonClickedRenderer.setAnchorPoint(point, y);
497+
this._buttonDisableRenderer.setAnchorPoint(point, y);
500498
}
499+
this._titleRenderer.setPosition(this._size.width * (0.5 - this._anchorPoint._x), this._size.height * (0.5 - this._anchorPoint._y));
501500
},
502501

503502
onSizeChanged: function () {

extensions/CocoStudio/GUI/UIWidgets/UICheckBox.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,20 @@ ccs.CheckBox = ccs.Widget.extend(/** @lends ccs.CheckBox# */{
389389
* @param {Number} [y] The anchor point.y of UICheckBox.
390390
*/
391391
setAnchorPoint: function (point, y) {
392-
if(arguments.length === 2){
393-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
394-
this._backGroundBoxRenderer.setAnchorPoint(point, y);
395-
this._backGroundSelectedBoxRenderer.setAnchorPoint(point, y);
396-
this._backGroundBoxDisabledRenderer.setAnchorPoint(point, y);
397-
this._frontCrossRenderer.setAnchorPoint(point, y);
398-
this._frontCrossDisabledRenderer.setAnchorPoint(point, y);
392+
if(y === undefined){
393+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
394+
this._backGroundBoxRenderer.setAnchorPoint(point);
395+
this._backGroundSelectedBoxRenderer.setAnchorPoint(point);
396+
this._backGroundBoxDisabledRenderer.setAnchorPoint(point);
397+
this._frontCrossRenderer.setAnchorPoint(point);
398+
this._frontCrossDisabledRenderer.setAnchorPoint(point);
399399
}else{
400-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
401-
this._backGroundBoxRenderer.setAnchorPoint(point);
402-
this._backGroundSelectedBoxRenderer.setAnchorPoint(point);
403-
this._backGroundBoxDisabledRenderer.setAnchorPoint(point);
404-
this._frontCrossRenderer.setAnchorPoint(point);
405-
this._frontCrossDisabledRenderer.setAnchorPoint(point);
400+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
401+
this._backGroundBoxRenderer.setAnchorPoint(point, y);
402+
this._backGroundSelectedBoxRenderer.setAnchorPoint(point, y);
403+
this._backGroundBoxDisabledRenderer.setAnchorPoint(point, y);
404+
this._frontCrossRenderer.setAnchorPoint(point, y);
405+
this._frontCrossDisabledRenderer.setAnchorPoint(point, y);
406406
}
407407
},
408408

extensions/CocoStudio/GUI/UIWidgets/UIImageView.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ ccs.ImageView = ccs.Widget.extend(/** @lends ccs.ImageView# */{
216216
* @param {Number} [y] The anchor point.y of UIImageView.
217217
*/
218218
setAnchorPoint: function (point, y) {
219-
if(arguments.length === 2){
220-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
221-
this._imageRenderer.setAnchorPoint(point, y);
219+
if(y === undefined){
220+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
221+
this._imageRenderer.setAnchorPoint(point);
222222
} else {
223-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
224-
this._imageRenderer.setAnchorPoint(point);
223+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
224+
this._imageRenderer.setAnchorPoint(point, y);
225225
}
226226
},
227227

extensions/CocoStudio/GUI/UIWidgets/UILabel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ ccs.Label = ccs.Widget.extend(/** @lends ccs.Label# */{
263263
* @param {Number} [y] The anchor point.y of UILabel.
264264
*/
265265
setAnchorPoint: function (point, y) {
266-
if(arguments.length === 2){
267-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
268-
this._labelRenderer.setAnchorPoint(point, y);
266+
if(y === undefined){
267+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
268+
this._labelRenderer.setAnchorPoint(point);
269269
} else {
270-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
271-
this._labelRenderer.setAnchorPoint(point);
270+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
271+
this._labelRenderer.setAnchorPoint(point, y);
272272
}
273273
},
274274

extensions/CocoStudio/GUI/UIWidgets/UILabelAtlas.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ ccs.LabelAtlas = ccs.Widget.extend(/** @lends ccs.LabelAtlas# */{
126126
* @param {Number} [y] The anchor point.y of UILabelAtlas.
127127
*/
128128
setAnchorPoint: function (point, y) {
129-
if(arguments.length === 2){
130-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
131-
this._labelAtlasRenderer.setAnchorPoint(point, y);
129+
if (y === undefined) {
130+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
131+
this._labelAtlasRenderer.setAnchorPoint(point);
132132
} else {
133-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
134-
this._labelAtlasRenderer.setAnchorPoint(point);
133+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
134+
this._labelAtlasRenderer.setAnchorPoint(point, y);
135135
}
136136
},
137137

extensions/CocoStudio/GUI/UIWidgets/UILabelBMFont.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ ccs.LabelBMFont = ccs.Widget.extend(/** @lends ccs.LabelBMFont# */{
9292
* @param {Number} [y] The anchor point.y of UILabelBMFont.
9393
*/
9494
setAnchorPoint: function (point, y) {
95-
if(arguments.length === 2){
96-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
97-
this._labelBMFontRenderer.setAnchorPoint(point, y);
95+
if(y === undefined){
96+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
97+
this._labelBMFontRenderer.setAnchorPoint(point);
9898
} else {
99-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
100-
this._labelBMFontRenderer.setAnchorPoint(point);
99+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
100+
this._labelBMFontRenderer.setAnchorPoint(point, y);
101101
}
102102
},
103103

extensions/CocoStudio/GUI/UIWidgets/UITextField.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ ccs.TextField = ccs.Widget.extend(/** @lends ccs.TextField# */{
560560
* @param {Number} [y] The anchor point.y of UILabelBMFont.
561561
*/
562562
setAnchorPoint: function (point, y) {
563-
if(arguments.length === 2){
564-
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
565-
this._textFieldRender.setAnchorPoint(point, y);
563+
if(y === undefined){
564+
ccs.Widget.prototype.setAnchorPoint.call(this, point);
565+
this._textFieldRender.setAnchorPoint(point);
566566
} else {
567-
ccs.Widget.prototype.setAnchorPoint.call(this, point);
568-
this._textFieldRender.setAnchorPoint(point);
567+
ccs.Widget.prototype.setAnchorPoint.call(this, point, y);
568+
this._textFieldRender.setAnchorPoint(point, y);
569569
}
570570
},
571571

0 commit comments

Comments
 (0)