Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Last active December 18, 2015 18:09
Show Gist options
  • Save drewlesueur/5823356 to your computer and use it in GitHub Desktop.
Save drewlesueur/5823356 to your computer and use it in GitHub Desktop.
Javascript's this
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