本文介绍了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,将回调绑定到任何函数
发布评论