先看看使用页面是如何调用的。
复制代码 代码如下:<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>neverModulesUsingFunction-http://www.never-online.net</title>
<metahttp-equiv="ImageToolbar"content="no"/>
<metaname="author"content="never-online,BlueDestiny"/>
<metaname="keywords"content="nevermodules,MozillaCSS,C#,.net,Reference,BlueDestiny,never-online"/>
<metaname="description"content="javascriptreference,csharpartilces"/>
<metaname="creator.name"content="never-online,BlueDestiny"/>
<styletype="text/css"media="all"title="Default">
body{
font:9pt"Verdana";
}
</style>
<scripttype="text/javascript"src="System/system.js"></script>
<scripttype="text/javascript">
//<![CDATA[
Using("System.Utils.Jsclass");
varjsclass=newJsclass();
jsclass.toString();
//]]>
</script>
</head>
<bodyid="www.never-online.net">
<palign="center">PowerBynever-online</a>
</body>
</html>
再看看System.Utils.Jsclass这个命名空间是如何的。
varSystem={};System.Utils={};
System.Utils.Jsclass=function(){
this.name="jsclass";
this.functions="Usingfunctiontest.";
System.Utils.Jsclass.prototype.toString=function(){
document.write(this.functions);
}
}
接下来就是主要的Using这个函数了
varUsing=function(sNamespace,bUseCache){
bUseCache=bUseCache===true;
varx=!!document.all?newActiveXObject("MSXML2.XMLHTTP"):newXMLHttpRequest();
varshortname=sNamespace.substring(sNamespace.lastIndexOf(".")+1);
sNamespace=sNamespace.replace(/./g,"/")+".js";
x.open("GET",sNamespace+(bUseCache?"?x="+Math.random():""),false);
x.send(null);varcode=x.responseText;
window[shortname]=window.eval(code);
}
下载此文件