Skip to content

Instantly share code, notes, and snippets.

@lgmcolin
Last active August 29, 2015 13:57
Show Gist options
  • Save lgmcolin/9906814 to your computer and use it in GitHub Desktop.
Save lgmcolin/9906814 to your computer and use it in GitHub Desktop.
merge-descripe简单实现属性继承 from: https://github.com/component/merge-descriptors
module.exports = function (dest, src) {
Object.getOwnPropertyNames(src).forEach(function (name) {
var descriptor = Object.getOwnPropertyDescriptor(src, name)
Object.defineProperty(dest, name, descriptor)
})
return dest
}
// called
var thing = {
get name() {
return 'jon'
}
}
var animal = {
}
merge(animal, thing)
animal.name === 'jon'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment