Skip to content

Instantly share code, notes, and snippets.

@teramako
Created January 27, 2013 13:35
Show Gist options
  • Save teramako/4648358 to your computer and use it in GitHub Desktop.
Save teramako/4648358 to your computer and use it in GitHub Desktop.
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