Skip to content

Instantly share code, notes, and snippets.

@ragmha
Created November 27, 2018 10:12
Show Gist options
  • Save ragmha/7e169d919e73d839b994f225b5e098a5 to your computer and use it in GitHub Desktop.
Save ragmha/7e169d919e73d839b994f225b5e098a5 to your computer and use it in GitHub Desktop.
// Function
function myFunction() {
console.log("Function::", this);
}
myFunction(); // => Window is invoking the function
// Lamda
const myanotherFunc = () => console.log("Lamda::", this);
myanotherFunc();
// Object literal
const myObj = {
myMethod() {
console.log("Object::", this);
},
};
myObj.myMethod(); // => myObj is invoiking the function
// Classes
class MyClass {
myMethod() {
console.log("Class::", this);
}
}
const myInstance = new MyClass();
myInstance.myMethod(); // => myInstance is invoking the function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment