Simple implementation of the using function like C # In JS (with source code download)

Source: Internet
Author: User

First, let's see how the page is called.
Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> neverModules Using Function-http://www.never-online.net </title>
<Meta http-equiv = "ImageToolbar" content = "no"/>
<Meta name = "author" content = "never-online, BlueDestiny"/>
<Meta name = "keywords" content = "never modules, Mozilla CSS, C #,. net, Reference, BlueDestiny, never-online"/>
<Meta name = "description" content = "javascript reference, c sharp artilces"/>
<Meta name = "creator. name" content = "never-online, BlueDestiny"/>
<Style type = "text/css" media = "all" title = "Default">
Body {
Font: 9pt "Verdana ";
}
</Style>
<Script type = "text/javascript" src = "System/system. js"> </script>
<Script type = "text/javascript">
// <! [CDATA [
Using ("System. Utils. Jsclass ");
Var jsclass = new Jsclass ();
Jsclass. toString ();
//]>
</Script>
</Head>
<Body id = "www.never-online.net">
<P align = "center"> Power By never-online </a>
</Body>
</Html>
Let's take a look at the namespace System. Utils. Jsclass.
Var System ={}; System. Utils = {};
System. Utils. Jsclass = function (){
This. name = "jsclass ";
This. functions = "Using function test .";
System. Utils. Jsclass. prototype. toString = function (){
Document. write (this. functions );
}
}
The next step is the main Using function.
Var Using = function (sNamespace, bUseCache ){
BUseCache = bUseCache === true;
Var x = !! Document. all? New ActiveXObject ("MSXML2.XMLHTTP"): new XMLHttpRequest ();
Var shortname = sNamespace. substring (sNamespace. lastIndexOf (".") + 1 );
SNamespace = sNamespace. replace (/\./g, "/") + ". js ";
X. open ("GET", sNamespace + (bUseCache? "? X = "+ Math. random ():" "), false );
X. send (null); var code = x. responseText;
Window [shortname] = window. eval (code );
}
Download this file

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.