0
我有一些代碼如下 -訪問JavaScript中的對象文字內的函數內的函數?
var app = {
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
document.addEventListener('backbutton',this.receivedEvent.backbutton(),false);
^-- //not working
},
onDeviceReady: function() {
this.receivedEvent('deviceready');
},
receivedEvent: function(id) {
var originalLocation, partnership;
function fadeOut(element, direction) {
....
};
function fadeIn(element, direction) {
.....
}
function formFadeIn(direction) {
fadeIn($("#dataform"), direction);
};
function formFadeOut(direction) {
fadeOut($("#dataform"), direction);
};
function backbutton() {
var current = $("#home").attr("page-current");
var prev = $("#home").attr("page-prev");
if (current == "dataform" && prev == "partnertype") {
formFadeOut("opposite");
partnertypeFadeIn("opposite");
setPage("country", "partnertype")
$("#selectcountry").attr("disabled", false).val("AF")
} else if (current == "dataform" && prev == "country") {
formFadeOut("opposite");
countryFadeIn("opposite");
} else if (current == "partnertype" && prev == "country") {
partnertypeFadeOut("opposite");
countryFadeIn("opposite");
} else {
window.location.reload()
}
}
}
};
app.initialize();
所以我需要綁定內receivedEvent
事件「後退按鈕」的function backbutton()
。 function backbutton()
正在調用receivedEvent
內的本地函數,如formFadeIn()
等
我無法弄清楚綁定的確切語法。
我已經試過 -
this.receivedEvent.backbutton
//沒有反應this.receivedEvent.backbutton()
//沒有反應this.receivedEvent.bind(this).backbutton
//導致無限循環的頁面- 上
導出backbutton()函數爲
return { backbutton : backbutton }
//沒有反應
我有什麼做的訪問從app.initialize()
function backbutton()
沒有鬆動的背景下?
myBackButtonFunction是靠調用包含在receivedEvent等功能 - 所以很遺憾這是不行的。 – rkmr