jQuery,将回调绑定到任何函数

编程入门 行业动态 更新时间:2024-10-18 21:22:59
本文介绍了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,将回调绑定到任何函数

本文发布于:2023-11-25 15:22:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   回调   函数   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!