Scope of JavaScript variables (XUL-related)
问题 A beginner's question, probably a trivial one. Here's the XUL code snippet: <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/javascript" src="chrome://.../main.js"/> <button label="Click me!" oncommand="clickhandler()"/> </window> The JavaScript code: // main.js var test = "Peanut butter"; // a global variable function clickhandler() { alert(test); } The interpreter processes the JavaScript file just after reading the main window's