JavaScript uses static scoping. This means that the functions are executed in the scope in which they are defined. This is important because any global values they refer to belong to the page in which they live. That is not necessarily the page that they were called from. This is only likely to cause any confusion when a multiple framed document is being rendered.
The function scope is the state of the scope chain as it was when the function was called, plus the call object added onto the end of the scope chain. The call object is the function being executed.
Because the call object is added to the scope chain, you don't need to refer to it explicitly and the current context inherits all its properties and methods.
The static properties of a regular expression object do not conform to the same static scoping rules. Their static or class based properties are dynamically scoped and available in the scope chain from which they are executed.
See also: | Event handler scope, RegExp object |
Prev | Home | Next |
Function prototype | Up | function( ... ) ... |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |