Last active
August 29, 2015 13:57
-
-
Save lgmcolin/9906814 to your computer and use it in GitHub Desktop.
merge-descripe简单实现属性继承 from: https://github.com/component/merge-descriptors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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