mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 22:01:58 -05:00
Restructure #initialize() in basic types to use direct arguments checking more than arguments.length.
This commit is contained in:
parent
404e61ebff
commit
fcb8242da8
3 changed files with 17 additions and 17 deletions
|
@ -23,10 +23,10 @@ var Point = this.Point = Base.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
initialize: function(arg0, arg1) {
|
initialize: function(arg0, arg1) {
|
||||||
if (arguments.length == 2) {
|
if (arg1 !== undefined) {
|
||||||
this.x = arg0;
|
this.x = arg0;
|
||||||
this.y = arg1;
|
this.y = arg1;
|
||||||
} else if (arguments.length == 1) {
|
} else if (arg0 !== undefined) {
|
||||||
if (arg0 == null) {
|
if (arg0 == null) {
|
||||||
this.x = this.y = 0;
|
this.x = this.y = 0;
|
||||||
} else if (arg0.x !== undefined) {
|
} else if (arg0.x !== undefined) {
|
||||||
|
|
|
@ -18,14 +18,14 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
initialize: function(arg0, arg1, arg2, arg3) {
|
initialize: function(arg0, arg1, arg2, arg3) {
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 4) {
|
||||||
// Use 0 as defaults, in case we're reading from a Point or Size
|
// new Rectangle(x, y, width, height)
|
||||||
this.x = arg0.x || 0;
|
this.x = arg0;
|
||||||
this.y = arg0.y || 0;
|
this.y = arg1;
|
||||||
this.width = arg0.width || 0;
|
this.width = arg2;
|
||||||
this.height = arg0.height || 0;
|
this.height = arg3;
|
||||||
} else if (arguments.length == 2) {
|
} else if (arguments.length == 2) {
|
||||||
if (arg1.x !== undefined) {
|
if (arg1 && arg1.x !== undefined) {
|
||||||
// new Rectangle(point1, point2)
|
// new Rectangle(point1, point2)
|
||||||
var point1 = Point.read(arguments, 0, 1);
|
var point1 = Point.read(arguments, 0, 1);
|
||||||
var point2 = Point.read(arguments, 1, 1);
|
var point2 = Point.read(arguments, 1, 1);
|
||||||
|
@ -50,12 +50,12 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
this.width = size.width;
|
this.width = size.width;
|
||||||
this.height = size.height;
|
this.height = size.height;
|
||||||
}
|
}
|
||||||
} else if (arguments.length == 4) {
|
} else if (arg0) {
|
||||||
// new Rectangle(x, y, width, height)
|
// Use 0 as defaults, in case we're reading from a Point or Size
|
||||||
this.x = arg0;
|
this.x = arg0.x || 0;
|
||||||
this.y = arg1;
|
this.y = arg0.y || 0;
|
||||||
this.width = arg2;
|
this.width = arg0.width || 0;
|
||||||
this.height = arg3;
|
this.height = arg0.height || 0;
|
||||||
} else {
|
} else {
|
||||||
// new Rectangle()
|
// new Rectangle()
|
||||||
this.x = this.y = this.width = this.height = 0;
|
this.x = this.y = this.width = this.height = 0;
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
|
|
||||||
var Size = this.Size = Base.extend({
|
var Size = this.Size = Base.extend({
|
||||||
initialize: function(arg0, arg1) {
|
initialize: function(arg0, arg1) {
|
||||||
if (arguments.length == 2) {
|
if (arg1 !== undefined) {
|
||||||
this.width = arg0;
|
this.width = arg0;
|
||||||
this.height = arg1;
|
this.height = arg1;
|
||||||
} else if (arguments.length == 1) {
|
} else if (arg0 !== undefined) {
|
||||||
if (arg0 == null) {
|
if (arg0 == null) {
|
||||||
this.width = this.height = 0;
|
this.width = this.height = 0;
|
||||||
} else if (arg0.width !== undefined) {
|
} else if (arg0.width !== undefined) {
|
||||||
|
|
Loading…
Reference in a new issue