Skip to content

Instantly share code, notes, and snippets.

@lisp-ceo
Created July 31, 2013 21:43
Show Gist options
  • Save lisp-ceo/6126456 to your computer and use it in GitHub Desktop.
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.
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