[Img] http://www.blogcn.com/User12/antsam/Upload/20041217142710.jpg [/img]
This is a relationship between the four important components of javascript:
Runtime, script, context, and Object
Note that objects can be shared between different contexts.
When using JS, you will surely think about how to call another
Is a function or variable defined in a JS file?
The old one needs to be implemented by sharing an object, and context enables the script to execute
Stack space (fixed me), the variables (global) and functions defined in this script
The information is saved in a gloabal object, so we only need
This article shares an object to implement the above problems.
For example:
Test. JS:
VaR m = 0;
Function addvalues1 (A, B)
{
Result = a + B + M + N;
M = m + 10;
Return result;
}
Test2.js:
VaR n = 100;
Function addvalues2 (A, B)
{
Result = a + B + N;
N = N + 10;
Result + = addvalues1 (A, B );
Return result;
}
Code:
......
Jsp1 = js_compilefile (CT1, globalobj, "test. js ";
Js_executescript (CT1, globalobj, jsp1, & rval );
Jsp2 = js_compilefile (CT2, globalobj, "test2.js ";
Js_executescript (CT2, globalobj, jsp2, & rval );
......
Js_callfunctionname (CT1, globalobj, "addvalues1", 2, argS, & rval );
......
Js_callfunctionname (CT2, globalobj, "addvalues2", 2, argS, & rval );
With this feature, we can define the syntax of our script:
In the sytax. js file, we define some interfaces (DOM ):
Beginmaterial (), endmaterial ()
Beginpass (), endpass ()
Then you can write the material script and execute it:
Beginmaterial ()
{
Beginpass ()
{
......
}
Endpass ()
Beginpass ()
{
......
}
Endpass ()
}
Endmaterial ()