Last active
December 12, 2018 01:58
-
-
Save MouseZero/13ee1a9387d67d295bec1e3382cebfe0 to your computer and use it in GitHub Desktop.
This file contains 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
// ==== 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