From fcb8242da886a349a05a3e163d7d890d03038680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 19 May 2011 20:37:04 +0100 Subject: [PATCH] Restructure #initialize() in basic types to use direct arguments checking more than arguments.length. --- src/basic/Point.js | 4 ++-- src/basic/Rectangle.js | 26 +++++++++++++------------- src/basic/Size.js | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/basic/Point.js b/src/basic/Point.js index 08f9aa97..aae54a8f 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -23,10 +23,10 @@ var Point = this.Point = Base.extend({ beans: true, initialize: function(arg0, arg1) { - if (arguments.length == 2) { + if (arg1 !== undefined) { this.x = arg0; this.y = arg1; - } else if (arguments.length == 1) { + } else if (arg0 !== undefined) { if (arg0 == null) { this.x = this.y = 0; } else if (arg0.x !== undefined) { diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 93669d34..0885b8eb 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -18,14 +18,14 @@ var Rectangle = this.Rectangle = Base.extend({ beans: true, initialize: function(arg0, arg1, arg2, arg3) { - if (arguments.length == 1) { - // Use 0 as defaults, in case we're reading from a Point or Size - this.x = arg0.x || 0; - this.y = arg0.y || 0; - this.width = arg0.width || 0; - this.height = arg0.height || 0; + if (arguments.length == 4) { + // new Rectangle(x, y, width, height) + this.x = arg0; + this.y = arg1; + this.width = arg2; + this.height = arg3; } else if (arguments.length == 2) { - if (arg1.x !== undefined) { + if (arg1 && arg1.x !== undefined) { // new Rectangle(point1, point2) var point1 = Point.read(arguments, 0, 1); var point2 = Point.read(arguments, 1, 1); @@ -50,12 +50,12 @@ var Rectangle = this.Rectangle = Base.extend({ this.width = size.width; this.height = size.height; } - } else if (arguments.length == 4) { - // new Rectangle(x, y, width, height) - this.x = arg0; - this.y = arg1; - this.width = arg2; - this.height = arg3; + } else if (arg0) { + // Use 0 as defaults, in case we're reading from a Point or Size + this.x = arg0.x || 0; + this.y = arg0.y || 0; + this.width = arg0.width || 0; + this.height = arg0.height || 0; } else { // new Rectangle() this.x = this.y = this.width = this.height = 0; diff --git a/src/basic/Size.js b/src/basic/Size.js index 68461aee..972a89f7 100644 --- a/src/basic/Size.js +++ b/src/basic/Size.js @@ -16,10 +16,10 @@ var Size = this.Size = Base.extend({ initialize: function(arg0, arg1) { - if (arguments.length == 2) { + if (arg1 !== undefined) { this.width = arg0; this.height = arg1; - } else if (arguments.length == 1) { + } else if (arg0 !== undefined) { if (arg0 == null) { this.width = this.height = 0; } else if (arg0.width !== undefined) {