Skip to content

Instantly share code, notes, and snippets.

@nikkaroraa
Created November 26, 2017 15:42
Show Gist options
  • Save nikkaroraa/2d59fef7b2cb33fcad6f045789ab6060 to your computer and use it in GitHub Desktop.
Save nikkaroraa/2d59fef7b2cb33fcad6f045789ab6060 to your computer and use it in GitHub Desktop.
this keyword
function globalFunction() {
console.log(this);
}
globalFunction(); //[object Window]
//globalFunction() is equivalent to window.globalFunction()
var myObj = {name: "obj"};
myObj.logThis = function () {
console.log(this);
}
myObj.logThis(); //[object myObj]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment