This is a consequence of Javascript function semantics: Any binding
in a function has block extent, so it's as if all var and function
declarations in a function body move to the top of the body. It's
pretty kludgey, because once your script block function reaches the
script compiler back-end, the function-local bindings are turned back
into global bindings, but the original ordering is already lost.
That's why this code worked.
What I'm not sure of is whether that is a bug or the bug is that
global var and function declarations should have the same behavior
(have global scope, be re-ordered so they happen before any top-level
expressions.
On 2007-01-15, at 22:51 EST, Henry Minsky wrote:
In the SOAP runtime library, there's a file included named
lps/components/rpc/library/qname.js
I was getting various errors running it in Legals, and I noticed
that it
defines some properties on the global
QName before it is defined to have any value.
QName.SUPPORTED_TYPES = {};
//--------------------------------------------------------------------
---------
// String representation of this QName.
//--------------------------------------------------------------------
---------
QName.prototype.toString = function () {
return "QName {" + this.__LZns + "}" + this.__LZlocal;
}
//
======================================================================
=======
// DEFINE OBJECT: QName
//
// Create a qualified name object.
//
// @param local: local part of the QName.
// @param namespaceURI: namespace URI for the QName.
//
======================================================================
========
function QName(local, namespaceURI)
{
this.__LZlocal = local;
this.__LZns = namespaceURI;
QName.SUPPORTED_TYPES[this.toString()] = true;
}
I moved the "function QName (...) {}" block to be the first thing
in the
file and it works properly.
How come this is working in trunk? It seems like QName is not defined
anyplace else. One other thing
I changed is that this code now uses the 'when="immediate"' option to
<script> tags that we just added.
But I don't see how that would make a difference.
--
Henry Minsky
Software Architect
[EMAIL PROTECTED]