Last active
August 23, 2019 18:47
-
-
Save jeremyckahn/440fd4b606cfbecd61d31db79ff1f29e to your computer and use it in GitHub Desktop.
Refresher on prototypal 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 Parent () { console.log('parent') } | |
Parent.prototype.parentMethod = function () { | |
console.log('this is a method on the parent object') | |
} | |
function Child () { console.log('child') } | |
Child.prototype = new Parent() | |
var child = new Child() | |
child.parentMethod() | |
// Modern way | |
class Parent { | |
parentMethod () { | |
console.log('this is a method on the parent object') | |
} | |
} | |
class Child extends Parent {} | |
const child = new Child() | |
child.parentMethod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment