Skip to content

Instantly share code, notes, and snippets.

@MouseZero
Last active December 12, 2018 01:58
Show Gist options
  • Save MouseZero/13ee1a9387d67d295bec1e3382cebfe0 to your computer and use it in GitHub Desktop.
Save MouseZero/13ee1a9387d67d295bec1e3382cebfe0 to your computer and use it in GitHub Desktop.
// ==== Class 1 ====
function Person(componentName) {
this.componentName = componentName
}
// talk will end up being in __proto__
Person.prototype.talk = function () {
console.log(this.name)
}
const john = new Person('div1')
john.name = 'john'
john.talk()
// ==== Class 2 ====
const Person2 = {
// componentName will end up being in __proto__
componentName: 'div2',
// talk will end up being in __proto__
talk: function () {
console.log(this.name)
}
}
const steve = Object.create(Person2)
steve.name = 'steve'
steve.talk()
// === Class 3 ===
class Person3 {
constructor(componentName) {
this.componentName = componentName
}
talk() {
console.log(this.name)
}
}
const ashley = new Person3('div3')
ashley.name = 'ashley'
ashley.talk()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment