Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created May 26, 2014 01:33
Show Gist options
  • Save nicholasf/a11a2640f6fe6c86a9e7 to your computer and use it in GitHub Desktop.
Save nicholasf/a11a2640f6fe6c86a9e7 to your computer and use it in GitHub Desktop.
Ah, Javascript ...
> l = require('lodash');
> cloneFoo = l.clone(foo)
{ one: 1, two: 2 }
> delete cloneFoo['one']
true
> cloneFoo
{ two: 2 }
> foo
{ one: 1, two: 2 }
> var changer = function(d) {
... copy = l.clone(d);
... delete copy['one'];
... }
> changer(foo)
> foo
{ one: 1, two: 2 }
> foo2 = {}
{}
> foo2.test = { one : 1 }
{ one: 1 }
> foo2
{ test: { one: 1 } }
> var changer2 = function(d) {
... d2 = l.clone(d);
... delete d2.test['one'];
... }
> changer2(foo2)
> foo2
{ test: {} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment