Skip to content

Instantly share code, notes, and snippets.

@FireyFly
Created March 8, 2012 13:08
Show Gist options
  • Save FireyFly/2000920 to your computer and use it in GitHub Desktop.
Save FireyFly/2000920 to your computer and use it in GitHub Desktop.
Object inheritance
var Base = {}
Object.defineProperty(Base, 'extend', {
enumerable: false,
value: function(obj) {
var descs = {}
Object.getOwnPropertyNames(obj).forEach(function(key) {
descs[key] = Object.getOwnPropertyDescriptor(obj, key)
})
return Object.create(this, descs)
}
})
var Foo = Base.extend({
getBar: function() { return this.bar }
})
var foo = Foo.extend({ bar:10 })
console.log(foo.getBar()) // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment