Created
December 8, 2019 11:41
-
-
Save autioch/5607011a2b394c82c1734c369d59c0a8 to your computer and use it in GitHub Desktop.
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 (userName) { | |
this.userName = userName; | |
this.present = function () { | |
console.log(`Hi, I'm ${this.userName}`); | |
} | |
this.greet = function(person){ | |
console.log(`Hello ` + person); | |
} | |
} | |
class PersonEs6 { | |
constructor(userName){ | |
this.userName = userName; | |
} | |
present(){ | |
console.log(`Hi, I'm ${this.userName}`); | |
} | |
greet(person){ | |
console.log(`Hello ` + person); | |
} | |
} | |
const myInstance1 = new Person('John'); | |
const myInstance2 = new Person('Jane'); | |
document.addEventListener('click', myInstance1.present); | |
document.addEventListener('click', myInstance1.present.bind(myInstance1)); | |
document.addEventListener('click', myInstance1.present.bind(myInstance2)); | |
document.addEventListener('click', myInstance1.present.bind()); | |
document.addEventListener('click', () => myInstance1.present()); | |
document.addEventListener('click', myInstance1.greet); | |
document.addEventListener('click', myInstance1.greet.bind(myInstance1)); | |
document.addEventListener('click', myInstance1.greet.bind(myInstance1, "Frodo")); | |
document.addEventListener('click', myInstance1.greet.bind(myInstance2, "Baggins")); | |
document.addEventListener('click', myInstance1.greet.bind()); | |
document.addEventListener('click', () => myInstance1.greet("Sam")); | |
myInstance1.present.call(myInstance1); | |
myInstance1.present.call(myInstance2); | |
myInstance1.greet.call(myInstance1); | |
myInstance1.greet.call(myInstance2); | |
myInstance1.greet.call(myInstance1, "Bilbo"); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment