Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 9
    It's a little more correct to say that every function call has a scope. In other words, what's confusing about this in Javascript is that it's not an intrinsic property of the function itself, but rather an artifact of the way the function is invoked. Commented Jun 27, 2010 at 14:34
  • @pointy thanks. what causes the most confusion about this in js is the fact that in all the languages used earlier (c#, c++), - this can't be manipulated n always points to the object instance whereas in js it depends and can be changed when invoking functions using func.call, func.bind etc. – Sushil Commented Jun 25, 2013 at 10:04
  • 2
    this does not reference a function's scope. this will reference a specific object (or possibly undefined), which as you've said can be changed using .call() or .apply(). A function's scope is (essentially, when simplified) which variables it has access to, and this depends entirely on where the function is declared and cannot be changed. Commented Jan 3, 2015 at 22:48
  • @Pointy: "It's a little more correct to say that every function call has a scope." Even more correct to say that functions (and now blocks) have scope, function calls have context. Scope defines what the identifiers are that can be used by code in that scope. Context defines what those identifiers are bound to. Commented Nov 14, 2015 at 15:09
  • 1
    "Whatever that scope is, is referenced by "this"." No, this and scope have nothing whatsoever to do with one another in ES5 and before (e.g., when this answer was written). In ES2015 (aka ES6), this and scope are related one fairly minimal way wrt arrow functions (the this in an arrow function is inherited from its enclosing scope), but this never refers to a scope. Commented Nov 14, 2015 at 15:09