core-extensions
Advanced tools
Comparing version 0.0.2 to 0.0.3
75
index.js
@@ -7,2 +7,32 @@ "use strict"; | ||
Object.defineProperty( Object.prototype, "clone", { | ||
enumerable: false, | ||
value: function () { | ||
var target = null; | ||
var type = typeof this; | ||
if ( this === undefined ) { | ||
target = undefined; | ||
} | ||
else if ( this === null ) { | ||
target = null; | ||
} | ||
else if ( type == 'string' || type == 'number' || type == 'boolean' ) { | ||
target = this; | ||
} | ||
else if ( this instanceof Date ) { | ||
target = new Date( this.toISOString() ); | ||
} | ||
else if ( Object.isObject( this ) || Array.isArray( this ) ) { | ||
target = JSON.parse( JSON.stringify( this ) ); // probably a slightly more efficient way to do this, but this is ok for now | ||
} | ||
else { // functions, etc. not clonable yet | ||
target = undefined; | ||
} | ||
return target; | ||
} | ||
} ); | ||
Object.defineProperty( Object.prototype, "mixin", { | ||
@@ -47,5 +77,14 @@ enumerable: false, | ||
// ...replace target array with a new array containing existing values and new values | ||
child[ name ] = target.concat( source ); | ||
// ...merge source array into target array | ||
for ( var j = 0; j < source.length; j++ ) { | ||
if ( typeof child[ name ][j] === 'object' ) { | ||
child[ name ][j] = child[ name ][j].mixin( source[j] ); | ||
} | ||
else { | ||
child[ name ][j] = source[j]; | ||
} | ||
} | ||
} | ||
@@ -63,3 +102,3 @@ | ||
child[ name ] = source; | ||
child[ name ] = source.clone(); | ||
@@ -76,34 +115,4 @@ } | ||
Object.defineProperty( Object.prototype, "clone", { | ||
enumerable: false, | ||
value: function () { | ||
var target = null; | ||
var type = typeof this; | ||
if ( this === undefined ) { | ||
target = undefined; | ||
} | ||
else if ( this === null ) { | ||
target = null; | ||
} | ||
else if ( type == 'string' || type == 'number' || type == 'boolean' ) { | ||
target = this; | ||
} | ||
else if ( this instanceof Date ) { | ||
target = new Date( this.toISOString() ); | ||
} | ||
else if ( Object.isObject( this ) || Array.isArray( this ) ) { | ||
target = JSON.parse( JSON.stringify( this ) ); // probably a slightly more efficient way to do this, but this is ok for now | ||
} | ||
else { // functions, regex, etc. not clonable yet | ||
throw "Cannot clone " + typeof this; | ||
} | ||
return target; | ||
} | ||
} ); | ||
@@ -5,3 +5,3 @@ { | ||
"author": "Anthony Hildoer <anthony@bluerival.com>", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5579
82