JS中简单的实现像C#中using功能(有源码下载)_Javascript教程-查字典教程网
JS中简单的实现像C#中using功能(有源码下载)
JS中简单的实现像C#中using功能(有源码下载)
发布时间:2017-01-14 来源:查字典编辑
摘要:先看看使用页面是如何调用的。复制代码代码如下:neverModulesUsingFunction-http://www.never-onli...

先看看使用页面是如何调用的。

复制代码 代码如下:<!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);

}

下载此文件

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类