Restructure #initialize() in basic types to use direct arguments checking more than arguments.length.

This commit is contained in:
Jürg Lehni 2011-05-19 20:37:04 +01:00
parent 404e61ebff
commit fcb8242da8
3 changed files with 17 additions and 17 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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) {