如何讓全局對象myLib
同時爲需要參數並返回布爾值的庫樣式函數(true/false),我們稱之爲容器爲其他,公衆可訪問的方法,像這樣:返回值並提供對內部定義方法的訪問的函數
window.myLib = (function(w){
//...
function on(arg, callback){
}
return function(arg1, arg2){
//returns true or false, based on calculation on arg1, arg2...
}
})(window)
myLib('something', 'somethingother')// will return true or false
myLib.on('somecondition', function(){})// note the on() method-that's what I'm trying to accomplish
或者我應該問,這是可能的嗎?