我之前从正在查看的 PhoneGap/cordova 文件中遇到了这个问题:
var app = {
initialize: function() {
this.bind();
},
bind: function() {
document.addEventListener('deviceready', this.deviceready, false);
},
deviceready: function() {
// This is an event handler function, which means the scope is the event.
// So, we must explicitly called `app.report()` instead of `this.report()`.
app.report('deviceready');
app.handleLogin();
},
}
我只是想知道这样做与在身体负载上执行的独立功能相比有什么好处?另外,如果我要在 jquery mobile 的“pagebeforeload”上运行一个函数,我将如何将其集成到上述模式中?如:
$( '#mainMenu' ).live( 'pagebeforeshow', function(event){
alert('pagebeforeshow');
});