Design of materail script (JavaScript 3)

Source: Internet
Author: User
[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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.