Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active May 26, 2020 12:02
Show Gist options
  • Save harrisonmalone/9e5a8765e532f192c2a5f6e3cf146bc4 to your computer and use it in GitHub Desktop.
Save harrisonmalone/9e5a8765e532f192c2a5f6e3cf146bc4 to your computer and use it in GitHub Desktop.
es5 syntax for inheritance
function Person(name) {
this.name = name
}
Person.prototype.greeting = function() {
console.log(`hi`)
}
function Arm(name) {
Person.call(this, name)
this.skin = true
}
Arm.prototype = Object.create(Person.prototype)
Arm.prototype.constructor = Arm
const arm = new Arm('harrison')
console.log(arm)
class Person {
constructor(name) {
this.name = name
}
greeting() {
console.log('hi')
}
}
class Arm extends Person {
constructor(name) {
super(name)
this.skin = true
}
}
const person = new Arm('harrison')
console.log(person.greeting())
// good article https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment