Created
July 31, 2013 21:43
-
-
Save lisp-ceo/6126456 to your computer and use it in GitHub Desktop.
Underscore's extend does not recursively copy child dependencies. This sucks if you want to create a deep copy of an object. This functionality doesn't exist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require( 'underscore'); | |
var obj1 = { | |
item : { | |
yolo : { | |
swag : { | |
trill : true | |
} | |
} | |
} | |
}; | |
var obj2 = _.extend({}, obj1); | |
console.log( 'obj1 === obj2:', obj1 === obj2 ); | |
console.log( 'obj1.yolo === obj2.yolo:', obj1.yolo === obj2.yolo ); | |
try { | |
console.log( 'obj1.yolo.swag === obj2.yolo.swag:', obj1.yolo.swag === obj2.yolo.swag ); | |
} catch( e ){ | |
console.log( 'obj1.yolo.swag === obj2.yolo.swag: exception' ); | |
} | |
try { | |
console.log( 'obj1.yolo.swag.trill === obj2.yolo.swag.trill:', obj1.yolo.swag === obj2.yolo.swag ); | |
} catch( e ){ | |
console.log( 'obj1.yolo.swag.trill === obj2.yolo.swag.trill: exception' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment