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

StackOverflow https://stackoverflow.com/questions/4725454

  •  12-10-2019
  •  | 
  •  

سؤال

I'm developing a small plugin that changes the favicons if there are unread messages in mailbox in 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/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top