Last active
December 18, 2015 18:09
-
-
Save drewlesueur/5823356 to your computer and use it in GitHub Desktop.
Javascript's this
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 = {name: "a", fun: function () { return this; }}; | |
console.log(a.fun()); | |
//=> {name "a", fun: ...} | |
var bFunc = function () { return this }; | |
var b = {name: "b", fun: bFunc}; | |
console.log(b.fun()); | |
//=> {name: "b", fun: ...} | |
// not some global object | |
var c = {name: "c", func: function () { return this; }}; | |
var cFunc = c.func; | |
console.log(cFunc) | |
//=> some global object, probably Window | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment