The wxJS runtime environment

When a JavaScript runtime is started a global object is created. This global object can be reached as 'wxjs'. This object can be compared with the window object in a browser. Properties and Methods on this global object can be called without specifying the global object. It's possible that there is more then one runtime. The apache module mod_wxjs creates a runtime for each virtual host. A runtime can't interchange objects with another runtime. The wxjs object is available during the lifetime of the runtime.

Because variables which are not declared with the 'var' keyword are stored in the active global object, a script gets a global object of its own. Otherwise the wxjs object gets polluted with variables and methods created during the execution of the script. If you want to create variables and methods on the wxjs global object, you have to set it explicitly. The global object of a script can be reached as 'script'. The script object is available during the lifetime of the script. When the script is finished, the script object will be gc'-ed. The script object can be compared with the document object in a webpage. The script object contains one predefined property: 'root'. This property contains the path of the main script.

Some examples to explain: Use the print method which is defined on the wxjs global object:

wxjs.print("Hello World\n");

is the same as

print("Hello World\n");

Define a variable without 'var' in a script:

foo = 1;
print(foo, "\n");

Is the same as:

foo = 1;
print(, "\n");

What when a function/property has the same name?

function print(text)
  wxjs.print("This is called from script.print: ", text);

print("Hello World\n");
script.print("Hello World\n");
wxjs.print("Hello World\n");

A variable that survives the execution of the script: = 1; Logo Support This Project




Need help? Ask you question in this group

Google Groups Beta
Find a bug? Report bugs
Need a feature? Feature requests
Support this project? Donate

Design downloaded from Free website templates, layouts, and tools.