Created
January 27, 2013 13:35
-
-
Save teramako/4648358 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function defineProperties (aTarget, aSource) { | |
var key, desc; | |
for (key of Object.getOwnPropertyNames(aSource)) { | |
desc = Object.getOwnPropertyDescriptor(aSource, key); | |
desc.enumerable = false; | |
Object.defineProperty(aTarget, key, desc); | |
} | |
return aTarget; | |
} | |
// example | |
function Foo(){} | |
defineProperties(Foo.prototype, { | |
getName: function(){ return this.name; }, | |
}); | |
function Bar(){} | |
Bar.prototype = defineProperties(Object.create(Foo.prototype), { | |
setName: function(val) { this.name = val; }, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment