I'm a little late here, but I thought I'd give an answer anyway and come up with something.
It is better not to think in terms of pointers and memory references when discussing the internal components of JavaScript (or ECMAScript) when working with specifications. Variables are records of the environment inside and are stored and referenced by name, not by memory address. What your assignment operator does, both internally and by design, looks for the name of the environment record ("foo" or "bar") and assigns the value to that record.
So,
var bar = function () { alert("A"); }
assigns the value "bar" for recording the environment (anonymous function).
var foo = bar;
internally calls GetValue ("bar"), which retrieves the value associated with the record "bar", and then associates this value with the record "foo". Therefore, subsequently, the original value of the bar can still be used, since it is now associated with foo.
Since JavaScript links are line by line, not memory address, that’s why you can do things like this:
someObject["someProperty"]
which searches for a value based on a property name.
Bob Feb 24 '10 at 19:35 2010-02-24 19:35
source share