Home >Web Front-end >JS Tutorial >Simple implementation in JS like using function in C# (source code download)_javascript skills
先看看使用页面是如何调用的。
Power By never-online
再看看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);
}
}
接下来就是主要的Using这个函数了
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);
}