See this document in the html specifications concerning the meaning of scripts embedded in an html document, regardless of scripting language.
When a body of JS code is found amid some html it is as if the code were replaced by the concatenated arguments to “document.write();” invoked within the interpreted JS code. Here is some obscure code to disabuse one of some alternate execution models.
Another mode of executing JS code is as fragments within html tags such as ‘<p onMouseOver="JS code">text</p>’. The idea is that the code runs when the cursor moves over the rendered text. They suggest that such code must be an invocation of a JS function, perhaps user defined. Such functions have arguments and I have not learned what environment those arguments are evaluated in.
This is conspicuous contrast to classic activation records which are each well bound to a specific body of code. In JS, I think, a body of code with free variables whose spelling matches the spellings of the struct names (called properties in JS) can be mated to the struct to form a procedure. Bizarre! I think JS was influenced by Self but I don’t know enough about Self to be sure.
Here is a little JS program that shows that curly braces do not limit scope as they do in C or Java. This code retrieves the value of “v” from the lexically correct frame in contrast to Lisp’s dynamic scoping. An assignment statement without “var” steps on outer values of that name. If you can explain this, let me know.
It appears from this that “this” is a pitfall—it is an obscure point that “person.sayName(x);” reveals members of person while “(person.sayName)(x);” does not.
Here the variable “firstName”, declared in an inner scope, has been smashed without explicitly exporting access thereto. The behavior of the expression “arguments.caller” depends on the browser. It is probably an insecure construct! Good news: it is broken!
When function x politely uses its private m, it preserves the caller’s m. This test indicates that free, non parameter identifiers in a function body are evaluated in the global scope.
You can nest function definitions and the inner definition seems local to the outer function. “m” which is free in the body of the inner function uses the variable declared in the outer function. Functions can return functions, and the invocation can be composed. Behold: λ, spelled “function”! Multiple generations also provide closures somehow. And even better, and best of all! Here is another multi environ demo. The Y combinator!
The <form> tag creates some sort of scope; see the source on this one.
See some security policy implemented in Netscape and Mozilla.
Tell Flash Player version to user.