Ahh.., so there was beforehand a .watch() method... !
Yes.
But not in Safari... etc right ?
Not yet, but Safari could add one at any moment. Opera's ECMAScript
implementation has - watch - and unwatch - methods on its object for
compatibility with JavaScript(tm), and Safari does do some things for
similar compatibility.
Not only (and that is assuming that "FireFox" is taken to mean all
Mozilla/Gecko based web browsers (and there are 20 odd of them by
now).
And, is that method a part of the standard ?
No. But the standard allows implementations to provide extensions and
those methods are an extension.
Why do you write ***JavaScript(tm)*** ?
JavaScript, with an uppercase J and an upper case S, is the trademark
name of what is now a single ECMAScript implementation (the one that
originated at Netscape, is now the responsibility of the Mozilla
foundation and appears in Firefox/Mozilla/Gecko browsers). There are
numerous other ECMAScript implementations, such as JScript(tm) in IE
browsers. I tend to use 'javascript' or 'Javascript' (with the non-
trademark capitalisation) to refer to geniality of ECMAScript
implementations (as do many others) and the trademark names to refer
to the specific implementations unambiguously (especially with the
"(tm)" extension) (were they have such names (and I know what those
names are)).
Hmm, I was expecting (function funcName () {})(); to yield a defined
funcName in that context.
But the specification says that should not happen. FunctionExpressions
and FunctionDeclarations are not handled the same way regardless of
how similar they may appear in some cases.
Which? Thinking it should create a named property of the variable
object or using the optional Identifiers with FunctionExpressions? The
former is a bad idea because it is at odds with the specification and
the reality of most implementations of that specification. The latter
is a bad idea because IE does not conform to the specification in this
area and what it does do is sufficiently strange as to be
problematic.
You could always have used an unnamed function instead,
I mean, if you didn't intend to get funcName defined... ?
The use of the optional Identifier with FunctionExpressions is to
allow code inside the function body to refer to the function object by
name (rather than using - arguments.callee -).
(function () {
var watch = aVar = "Hola !";
(function f () {
alert(aVar);
alert(watch);
alert(typeof f);
})();
alert(typeof f);
^^^^^^^^^^^^^^
Try moving this line to above the evaluation of the function
expression to see how badly IE is behaving here.
})();
IE8b : "Hola !", "Hola !", "function", "function" <- You're right,
IE did it !
<snip>
Yes, and if you it you would discover that the function object that
results form the evaluation of the function expression is not the same
function object as can be referred to using the Identifier in the
containing context.