Last active
September 6, 2017 17:58
-
-
Save doug2k1/43245ab6dad80bfb66a4f121d4968c71 to your computer and use it in GitHub Desktop.
'this' no JavaScript: global - https://blog.dmatoso.com/javascript-this-71dd763aad52
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
// Constante no objeto 'window' | |
window.playerName = 'Tidus' | |
const sayGlobalName = function () { | |
console.log(this.playerName) | |
} | |
// A chamada abaixo não se enquadra a nenhuma das outras regras, | |
// portanto o 'this' na função é o objeto global | |
// ('window' no navegador ou 'global' no Node.js) | |
sayGlobalName() // Tidus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment