function firstCallme(iWantToBePassed) {
post(callbackFun);
}
// This function shouldn't be anonymous.
function callbackFun(dataFromPostFun) {
alert(iWantToBePassed);
}
如何将变量iWantToBePassed从firstCallme()传递给callbackFun()?SO中有几个类似的问题。但我无法从中找出解决方案。
我只知道一种解决方案,如下所示:
function firstCallme(iWantToBePassed) {
post(function(data){callbackFun(data,iWantToBePassed) });
}
// This function shouldn't be anonymous.
function callbackFun(dataFromPostFun, iWantToBePassed) {
alert(iWantToBePassed);
}
有没有更好的解决方案?
更新:
这里:
function post(callbackFun) {
jQuery.post('url', 'data', callbackFun, 'json');
}