views:

105

answers:

2

In the vernacular, scope and context have a lot in common. Which is why I get confused when I read references to both, such as in the quote below from an article on closures:

Scope refers to where variables and functions are accessible, and in what context it is being executed. (@robertnyman)

As far as I can tell, context is just a reference to an object.

Can someone please explain what exactly is context, as used, for instance, in the jQuery syntax, $(selector, context). And is an object's scope the same at it's context?


Update:

I found this interesting article that talks about both scope and context in JavaScript.

http://www.digital-web.com/articles/scope_in_javascript/

+4  A: 

"Context", as used in this jQuery example, is not a JavaScript term. It is just the name of a variable. It is documented with the rest of the jQuery documentation: http://api.jquery.com/jQuery/#selector-context

David Dorward
Thanks, though it says:"However, an alternate **context** can be given for the search by using the optional second parameter to the $() function."They still seem to be referring to **context** with that variable.
DKinzer
Yes. It still isn't a JavaScript term. As it says, by default it searches "starting at the document root" (i.e. the default context is the document root). You can change that.
David Dorward
+1  A: 

"context" can mean many things. In the jQuery example you quote it is a reference to a part of the DOM that the selector should be applied to, which has nothing to do with JavaScript contexts.

Jakob Kruse