jQuery,将回调绑定到任何函数 [英] jQuery , bind a callback to any function
本文介绍了jQuery,将回调绑定到任何函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够将回调函数绑定到先前定义的函数
,并且能够使用在该函数范围内定义的两个变量。
I would like to be able to bind a callback function to a previously defined function and being able to use two variables defined in the scope of that function.
它应如下所示:
function mainFunction(){
var localForMain;
}
$(document).ready(function(){
// bind a call back method to the 'mainFunction'
$(mainFunction).bindCallback(function(){
// ...use the localForMain variable HERE;
});
});
是否有可能实现这样的目标?
Is it possible to achieve something like this?
推荐答案
以这种方式绑定回调函数是不可能的。你必须在函数内编程。
it is not possible to bind call back function in such way. You have to program it inside the function.
function SampleWithCallBack(callbackfunction)
{
code here
callbackfunction(params);
}
关于在上下文中使用已定义变量的问题。你应该在参数中传递变量或者在全局定义它,这不是一个很好的方法
about the use of defined variable in the context. You should pass the variables in parameters or define it globally which is not a very good way
这篇关于jQuery,将回调绑定到任何函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文