Last active
August 29, 2015 14:15
-
-
Save pr00thmatic/5208b9218df9de81e527 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
var a = (function () { | |
// "this" se refiere a la función instantánea anónima | |
this.x = 100; | |
var a = 1; | |
var showX = function () { | |
// el valor de "this" depende de quién | |
// invoque a esta función | |
console.log(this.x); | |
}; | |
var setX = function () { | |
// el valor de "this" depende de quién | |
// invoque a esta función | |
this.x = -100; | |
}; | |
showX(); // 100 | |
// como el valor de "this" en showX depende de quién | |
// lo invoque, en este execution context, "this" se | |
// refiere a la función anónima instantánea. | |
return { | |
a : a, | |
setX : setX, | |
showX : showX | |
}; | |
})(); | |
console.log(a.x); // undefined | |
a.setX(); | |
// como el valor de "this" en showX depende de quién | |
// lo invoque, en este execution context, "this" se | |
// refiere a la variable a. | |
console.log(a.x); // -100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment