我有一个这样的命名空间设置:
var myApp = {};
(function(context) {
var id = 0;
context.next = function() {
return id++;
};
context.reset = function() {
id = 0;
}
})(myApp);
window.console && console.log(
myApp.next(),
myApp.next(),
myApp.reset(),
myApp.next()
) //0, 1, undefined, 0
我现在想从 myApp 获得一个回调,我可以在命名空间之外捕获它。
任何想法如何使用我的命名空间设置进行设置?
例如这样的:
myApp.setCallback('next', function() {
alert('hello');
});