0
我對實現以下最佳實踐有點困惑: 我有一個需要加載2個JS庫(jQuery和swfobject)的對象,他們可能已經加載或沒有,所以我有在調用最終方法(輸出)之前檢查兩者。 另一個棘手的事情是,我必須傳遞一些參數到初始方法(gen),這些參數必須傳遞到輸出。我應該使用.apply嗎?回調結構
var myfancymethod = {
zclk: "string1",
zclk2: "string2",
loadsrc: function(what){
jQuery.getScript(what, function() {
alert (what+ "loaded");
});
},
checklibs: function(){
if (typeof libA == "undefined") {
this.loadsrc("libA.js");
}
if (typeof libB == "undefined") {
this.loadsrc("libB.js");
}
},
output: function (a, b, c){
//final output here
},
gen: function(a, b, c, d){
//have to check if libray A and B are loaded
this.checklibs();
//call to output()
?
}
myfancymethod.gen(a, b, c, d);