(function (APIName1,APIName2) {
var that=this;
var ClassAPI={};
var thatAPI={};
thatAPI.new$API = function (callback) {
ClassAPI = (function (mod) { callback(mod); return mod; })(ClassAPI || {});
};
thatAPI.insert= function () {
for(var i=0;i<arguments.length;i++){
var obj=arguments[i];
for(var key in obj){ if(!ClassAPI[key]){ ClassAPI[key]=obj[key]; }else{ for(var key2 in obj[key]){ if(!ClassAPI[key][key2]){ ClassAPI[key][key2]=obj[key][key2]; } } } }
}
};
that[APIName1]=thatAPI;
that[APIName2]= function (data,callback) { ClassAPI.data=data; return callback(ClassAPI); };
})('$APIFUN','$API');
var b={a: function () { console.log(11); }};
var c={c: function () { console.log(11); }};
var k={c: function () { console.log(11); }};
//引入新接口
$APIFUN.insert({a:b,b:k},{a:c});
创建新街口
$APIFUN.new$API(function (mod) { mod.aa= function (obj) { if(!obj){ console.log(mod.data); }else{ console.log(obj); } }; });
//调用接口
var kks=$API({a:22}, function (mod) { var dd= mod.data;//获取外部传入参数 mod.a.a(); mod.a.c(); mod.b.c(); mod.aa(); mod.aa(dd.a); return '123'; });
console.log(kks);
简单定义js类并调用,防止全局污染
最新推荐文章于 2023-09-02 16:41:30 发布