See this document in the html specifications concerning the meaning of scripts embedded in an html document, regardless of scripting language.
I have been following the elementary JavaScript introduction from Macromedia, now Adobe. So far the idea is that you mix JS (JavaScript) in with html and fancy things happen. Html is roughly a descriptive or declarative language and JS is a imperative or procedural language. It is not clear how these mix and that is, I think, at the root of some of variance of JS semantics between browsers. A language with assignment statements must be clear about order of execution.
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.
Here is a gentle introduction to Domain Object Model (DOM) which is another way to include JavaScript in web pages and thereby achieve more refined reflexes to user acts.
See Netscape’s Core JavaScript Guide for a definition of objects and functions in general, and Reference for particular standard objects.
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.
In C++ method names found at call sites and method names found at method definitions are associated at compile time and the results are conveyed in the compiled code as offsets into vtables. In JavaScript this association is dynamic as is even what “class” a given object belongs to. Java goes halfway in this regards with its Interface construct where the matching of method names happens at runtime because vtable layouts could not be coordinated earlier.
The Read-Eval-Print loop helps explore JavaScript. Enter expressions such as “window”, “window.statusbar”. Gripe about documentation
See some security policy implemented in Netscape and Mozilla.
Tell Flash Player version to user.
getElementById
The Actors Connection JavaScript seems always to define its actions and queries to named objects and avoid implicit global state, named or unnamed. This is good. Even the thing they call _global is global only in name. The fact that they speak as if there is only one does not preclude there being more than one. Indeed ActionScript introduces another layer. The architecture thus conforms to the actors idea that actions and queries can be only about acquaintances that are explicitly identified either by the program or by the semantics of the built-in object. I think that they miss by providing the “arguments.caller” construct. Actors significantly omits any such construct and gains security thereby. (2007: I see here that the feature has been somewhat defanged. There remains the issue that my calling you should not enable you to call me. This construct seems to be banished from JavaScript 2.0.)
The Keykos Connection ActionScript objects are very much like the nodes of Keykos. Where nodes have slots, ActionScript objects have properties. These two parallel constructs provide the mutable state of the respective systems. It is sort of important that nodes always have exactly 16 slots whereas objects have a variable number of properties. In each case there are other state carriers; Keykos has pages and JavaScript has arrays. The arguments.caller problem can be described in terms of the security implications of a resume key providing means of acquiring the start key to the domain designated by the start key.
See JavaScript Synergy with Firefox.