Skip to content

Instantly share code, notes, and snippets.

@jed
Forked from 140bytes/LICENSE.txt
Created May 13, 2011 06:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jed/970086 to your computer and use it in GitHub Desktop.
Save jed/970086 to your computer and use it in GitHub Desktop.
extend/unextend objects
function e(
a, // the source object
b, // the target object to be extended
c, // (placeholder)
d // (placeholder)
){
b = b || this; // extend the global object by default, and
d = {}; // create a cache for the current objects.
for (c in a) { // for each property on the target object,
d[c] = b[c]; // save it on the cache object,
b[c] = a[c] // and replace it with the source object.
};
return { // for hygiene's sake, return
undo: function() { // an undo function
e(d, b) // that reverts the changes.
}
}
}
function e(a,b,c,d){b=b||this;d={};for(c in a){d[c]=b[c];b[c]=a[c]};return{undo:function(){e(d,b)}}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "extend",
"description": "extend/unextend object properties",
"keywords": ["extend", "object", "properties"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment