Joe said:
Trevor L. wrote:
function showPage()
{
if(document.all)
{
document.all("wait").style.visibility="hidden"
document.all("mainpage").style.visibility="visible" }
else if(document.getElementById)
{
document.getElementById("wait").style.visibility="hidden"
document.getElementById("mainpage").style.visibility="visible" }
else if(document.layers)
{
document.layers("wait").visibility="hidden"
document.layers("mainpage").visibility="visible" }
}
//------------------------------
The interesting thing is that square brackets do not work in Firefox.
I therefore think that Firefox accepts document.all("wait")
but not document.all["wait"].
Actually the reverse is true. The first is a method call, while the
second is a property accessor. Firefox (at least the latest version)
will function with the property accessor, but only to provide
compatibility with badly written 'IE only' web sites.
FireFox is not executing that branch. Well written javascript test for
the existence of browser features before using them, so to avoid
exposing their - document.all - kludge to well written code the test -
if(document.all) - returns false, even though the a - document.all -
collection is implemented.
Modernness has nothing to do with it. document.getElementById - is W3C
Core DOM standard so modern browsers should be expected to implement it.
document.all - is Microsoft proprietary DOM and other browsers implement
it, or not, to provide some compatibility with IE, and sometimes in a
way that only works with property accessor syntaxes rather than method
calls.
Which strict syntax? In ECMAScirpt - document.all['anything'] - is a
bracket notation property accessor (the more flexible alternative to a
dot notation property accessor) and - document.all("anything") - is a
method call with an argument. They are completely different operations;
that they may result in the same value in some environments is entirely
down to the implementation. Remember that in ECMAScript a function is an
object, and may have properties that may be referenced with property
accessors.
document.all is a collection, the square brackets specify
the key of which element to retrieve. document.getElementById
is a method which accepts the id of the element required,
as all methods it uses parentheses. Had you used my
suggestion you'd have seen which one was called. IE often
accepts parentheses when brackets are needed according to
the ECMAScipt specs but I don't think the reverse applies.
It is not so much a matter of accepting parentheses where brackets would
be needed (that would be blowing the language syntax apart), but
providing a collection that can also be called. Approximately the
equivalent of:-
document.all = function(name){
return arguments.callee[name];
};
document.all['anElement'] = document.all[0] = DOM_Element_Ref_1;
document.all['anotherElement'] = document.all[1] = DOM_Element_Ref_2;
// and so on ... (with an assignment to - document.all.length -
// at some point, and maybe the provision of - item - and
// - namedItem - methods for the function object)
var firstEl = document.all['anElement'];
var secondEl = document.all('anotherElement');
// The method call would be expected to be slower due to the
// overheads in entering a new execution context.
With first-class functions in javascript that are also objects, having
an object that can be called also provide public members that can be
referenced with property accessors is completely viable. Indeed,
calling - typeof - on the - document.all - collection in Mac IE 5,
Opera, IceBrowser, and some others, will return "function", exposing how
these collections really work.
Richard.