Here was the primordial root of the Netscape documentation.
These notes by Doug Crockford are earlier than mine.
See Lint for JavaScript!

What does it mean to execute JavaScript Code

This was written late 2005.

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.

Notes from reading the ECMA definition

A JS program seems to have no fixed binding between defining and applied occurrences of an identifier or variable. Languages with lexical scoping associate just one defining occurrence of each identifier with each applied occurrence of that identifier. In JS there is, conceptually at run time, a function that takes a function body, in the form of a string, and returns a corresponding function object. I have not yet learned from the ECMA definition how free variables, that are not parameters, in that body are interpreted. Section 10.6 (page 46) says that When a value is to be returned from the call to a function, its activation object is no longer needed and may be permanently decommissioned.. This is not so for it may still be accessible. Neither JavaScript nor ActionScript seem to fallen into this error. “Values, Variables, and Literals” from Netscape is easier to read on these matters.

See Netscape’s Core JavaScript Guide for a definition of objects and functions in general, and Reference for particular standard objects.

One way to describe the JS computational model is to say that it conflates the activation record with a struct. The new operator precedes a function invocation in such a way as to seize and preserve the resulting activation record. Variables local to the function become fields of the struct. The new struct is divorced from the routine whose activation record it was. Such a struct is its own shape and is free to grow or shrink. There is no prototype or declaration to which it must conform. The JS construct object subsumes activation records and structs.

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.

Here are some thoughts on JavaScript & ActionScript that try to cast that architecture in terms familiar to me.

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.

See note on Inheritance. See seeking built in objects, See a style note for access control.
External: Google fractal: HTML5