Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Created September 26, 2013 07:53
Show Gist options
  • Save Cycymomo/6711087 to your computer and use it in GitHub Desktop.
Save Cycymomo/6711087 to your computer and use it in GitHub Desktop.
140bytes, completeObjectClone polyfill
function(
a, // object to clone
b // placeholder
){
with(Object) // import Object.*
return getOwnPropertyNames(a) // get property names
.map(b=function(c){ // iterate names
b[c]=getOwnPropertyDescriptor(a,c) // get descriptors
}),
create(getPrototypeOf(a),b) // get proto and create clone
}
function(a,b){with(Object)return getOwnPropertyNames(a).map(b=function(c){b[c]=getOwnPropertyDescriptor(a,c)}),create(getPrototypeOf(a),b)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
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": "completeObjectClone",
"description": "Fully clones an object using Object.create, Object.getPrototypeOf, Object.getOwnPropertyNames, and Object.getOwnPropertyDescriptor.",
"keywords": [
"es5",
"object",
"descriptor",
"prototype",
"clone"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment