Last active
May 26, 2020 12:02
-
-
Save harrisonmalone/9e5a8765e532f192c2a5f6e3cf146bc4 to your computer and use it in GitHub Desktop.
es5 syntax for inheritance
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 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