Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created Aug 9, 2012
Embed
What would you like to do?
A proper clone
// example: http://jsfiddle.net/QVqHs/
function clone(o) {
return Object.create(
Object.getPrototypeOf(o),
getOwnPropertyDescriptors(o)
)
}
function getOwnPropertyDescriptors(o) {
return Object.keys(o).reduce(getPropertyDescriptor.bind(o), {})
}
function getPropertyDescriptor(acc, key) {
acc[key] = Object.getOwnPropertyDescriptor(this, key)
return acc
}
@domenic

This comment has been minimized.

Copy link

@domenic domenic commented Aug 9, 2012

Nice trick passing a "third argument" to getPropertyDescriptor.

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