我有以下的JS对象:使用`this`在JS对象
var livePage = {
delay: 1000,
loadTables: function(){
loadTable($("#vbeTable"),'getUpdateA')
loadTable($("#vbcTable"),'getUpdateB')
createAlertDialog();
},
setClicks: function(){
$(".expand").live('click',function(){
expand($(this).attr('expandvalue'));
})
$(".launch")
.click(function(){
newPopup('index.php',1120,550);
});
$('.edit').live('click',function(){
openColPick($(this).attr('colType'))
});
},
setRightClick: function(){
$('body').contextMenu('mainmenu', {
bindings: {
'o_o': function(t) {
thePopupWindowsMain('oo','','',220,150,'right','');
},
'o_h': function(t) {
thePopupWindowsMain('oh','','',285,385,'left','');
},
'launch_prog': function(t) {
$(".launch").click();
},
'logout': function(t){
window.top.location = 'logout.php';
}
}
});
},
setWindow: function(){
$(window)
.resize(function() {
$('body').css('height', $(this).height())
alertToCorner();
})
.scroll(function(){$(this).resize()});
$(window).resize();
},
checkLogout: function(){
$.ajax({
url: 'getLogin.php',
dataType: "html",
success: function(data){
if($.trim(data) == 'LOGOUT'){
window.location = 'logout.php';
}
},
complete: function(){
setTimeout(function() {
livePage.checkLogout();},
livePage.delay)
},
timeout: 2000
});
},
init: function(){
this.checkLogout();
this.loadTables();
this.setClicks();
this.setRightClick();
this.setWindow();
console.log(this);
}
}
出于某种原因,在checkLogout: function()
我必须使用livePage.delay
和livePage.checkLogout()
当我尝试使用例如this.checklogout()
我得到以下错误在Chrome的控制台中:
Uncaught TypeError: Object [object DOMWindow] has no method 'checkLogout'
我该如何解决这个问题?
谢谢!
这工作:-)我添加了'var self = this;'到'checkLogout()'fn的顶部,并且我使用self而不是'this'谢谢^ _^ – Neal 2011-03-29 17:26:03