开发者

Having a callback when a function is called without touching the actual function (jquery)?

I'm developing a small plugin that changes the favicons if there are unread messages in mailbox in开发者_Python百科 Roundcubemail. However, the API sucks, and the event listupdate is fired only when the whole page is loaded, even if it is meant to fire when the list is updated.

However, I've managed to find out, that every time the list is updated, certain functions are called, such as set_unread_count. It gets the unread-count easily, so it would be great to somehow "append" stuff to this function. I just think based on hours of searching that there is no solution for this. Can I add a callback to be called when the set_unread_count is called? Can I somehow append stuff to that function? Any other ideas?


Create a little hook.

var _old_set_unread_count = set_unread_count;
set_unread_count = function() {
    // do whatever you want here
    // access arguments[x] to get arguments.

    _old_set_unread_count.apply(this, arguments);
};

Demo: http://www.jsfiddle.net/4yUqL/69/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜