Skip to content

Instantly share code, notes, and snippets.

@lovetingyuan
Created August 24, 2020 05:49
Show Gist options
  • Save lovetingyuan/1e947dbaab646f8c160b3f191e30e3e5 to your computer and use it in GitHub Desktop.
Save lovetingyuan/1e947dbaab646f8c160b3f191e30e3e5 to your computer and use it in GitHub Desktop.
Javascript extend
function Parent (name) {
this.name = name
}
Parent.prototype.getName = function getName () { return this.name }
function Child (name, age) {
Parent.call(this, name)
this.age = age
}
Child.prototype = Object.create(Parent.prototype, {
constructor: {
writable: true, configurable: true, enumerable: false,
value: Child
}
})
Child.prototype.getAge = function getAge () { return this.age }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment