0
我知道我可以使用回調是這樣的:的JavaScript回調
function foo(mySuccess) {
$.post('handler.ashx', mySuccess);
}
但我怎麼會在以下情況下做到:
function foo(){ }
$.post('handler.ashx', function(){
foo.mySuccess = function(data); //this wont work, but you get the idea
});
,然後使用叫它:
foo.mySuccess(function(data){
});
我認爲值得注意的是,除非使用'Function.prototype.bind',否則函數將失去綁定。 –
@RenatoZannon你是什麼意思? – Neal
如果'foo.mySucess'使用'this',當它被稱爲回調函數時,它將是'null'或'window'(而不是'foo')。這是一個常見的問題 –