开发者

Chaining functions in a jQuery plugin

I wrote a small plugin to handle text-to-input-to-text fields for on-the-fly editing, and it includes arguments that allow a user to run functions at different intervals of the process.

I want the user to be able to click the "actuator" (开发者_如何转开发the element that controls the process), and choose to have an intervening function run after the button is clicked (Function A) and another to run after the field has been turned back into standard text (Function B).

The assumption is that Function A will generally contain some sort of asynchronous call. How do I make it so that Function B is forced to run after Function A completes? I'm trying to avoid situations where certain values have to be passed to "flag" a function as ready.


Since there hasn't been an answer yet, I'll give it a shot. I think I know what you are trying to do.

All your async calls will have an optional callback. So you can call a function in that or you can also setup some custom events.

http://api.jquery.com/bind/

Then you can 'bind' things to those events. So other functions call when that event or function calls. Essentially event handlers & listeners.

So as different things happen in your application just have things listening to the events, and toggling themselves on or off on whether they can be activated or used at any given time.

You could also do this as I think you were initially attempting with using boolean flags but that could get pretty messy depending on how many you have.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜