Skip to content

Instantly share code, notes, and snippets.

@nuragic
Created October 31, 2012 15:24
Show Gist options
  • Save nuragic/3987645 to your computer and use it in GitHub Desktop.
Save nuragic/3987645 to your computer and use it in GitHub Desktop.
underscore.js _.extract()
/**
* Creates as many variables as object properties in the specified context.
*
* _.extract({name: "Andrea", address: "Madrid", age: "27"}, window);
* console.log(name)
* => 'Andrea'
*/
_.mixin({
extract: function(object ,context) {
for (var k in object) {
context[k] = object[k];
}
return object;
}
});
@JeancarloFontalvo
Copy link

Nice 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment