Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Last active August 23, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyckahn/440fd4b606cfbecd61d31db79ff1f29e to your computer and use it in GitHub Desktop.
Save jeremyckahn/440fd4b606cfbecd61d31db79ff1f29e to your computer and use it in GitHub Desktop.
Refresher on prototypal inheritance
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