Use 'in' operator instead of typeof checks in basic type constructors.

This commit is contained in:
Jürg Lehni 2012-11-10 16:32:37 -08:00
parent a676d3d5c6
commit f871430018
3 changed files with 12 additions and 12 deletions

View file

@ -145,16 +145,16 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
if (this._read)
this._read = arg0 === null ? 1 : 0;
} else {
if (typeof arg0.x !== 'undefined') {
this.x = arg0.x;
this.y = arg0.y;
} else if (Array.isArray(arg0)) {
if (Array.isArray(arg0)) {
this.x = arg0[0];
this.y = arg0.length > 1 ? arg0[1] : arg0[0];
} else if (typeof arg0.width !== 'undefined') {
} else if ('x' in arg0) {
this.x = arg0.x;
this.y = arg0.y;
} else if ('width' in arg0) {
this.x = arg0.width;
this.y = arg0.height;
} else if (typeof arg0.angle !== 'undefined') {
} else if ('angle' in arg0) {
this.x = arg0.length;
this.y = 0;
this.setAngle(arg0.angle);

View file

@ -71,7 +71,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
this.x = this.y = this.width = this.height = 0;
if (this._read)
this._read = arg0 === null ? 1 : 0;
} else if (arguments.length > 1 && typeof arg0.width === 'undefined') {
} else if (arguments.length > 1 && !('width' in arg0)) {
// We're checking arg0.width to rule out Rectangles, which are
// handled separately below.
// Read a point argument and look at the next value to see wether

View file

@ -106,13 +106,13 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
if (this._read)
this._read = arg0 === null ? 1 : 0;
} else {
if (typeof arg0.width !== 'undefined') {
this.width = arg0.width;
this.height = arg0.height;
} else if (Array.isArray(arg0)) {
if (Array.isArray(arg0)) {
this.width = arg0[0];
this.height = arg0.length > 1 ? arg0[1] : arg0[0];
} else if (typeof arg0.x !== 'undefined') {
} else if ('width' in arg0) {
this.width = arg0.width;
this.height = arg0.height;
} else if ('x' in arg0) {
this.width = arg0.x;
this.height = arg0.y;
} else {