我一直在努力实例化js库,然后调用启动对象>方法调用。
我必须像这样启动js库吗?
var objInstance = new banner.BannerLib({
‘name’: ‘topBanner’,
‘size’: 30,
‘color’: ‘red’
}); // how will be the structure of banner, and bannerlib is constructor?
然后这样打电话?
objInstance.show(); // show将是横幅中的方法,如何在横幅中定义?
问题:1。如何将lib / function结构用于横幅?有人可以提供示例代码吗? 请记住,我必须启动代码......完全相同。不喜欢var ob = new banner();答案 0 :(得分:1)
我试着做点事情
var banner ={};
banner.show = function(){
console.log("show somethings");
};
banner.BannerLib = function(a){
a || ( a = {});
this.name = a.name || "Default Name";
this.size = a.size || "Default Size";
this.color = a.color || "BLUE";
// Maybe something you need to initialize
};
banner.BannerLib.prototype.show = function(){
banner.show();
};
var obj = new banner.BannerLib({"name":"test", "color":"red",'size':21});
希望它能帮到你