Extending a jquery plugins event callback
- by Greg J
I'm extending the functionality of a jquery plugin (foo) with another jquery plugin (bar).
Essentially, the first plugin specifies an onReady():
var foo = $.foo({ onReady: function() { alert('foo'); }});
Foo is sent to bar as a parameter to bar:
var bar = $.bar(foo);
I want bar to be able to hook into foo's onReady event:
(function($) {
  $.extend({
    bar: function(foo) {
      var foo = foo;
      // How to do alert('bar') when foo.onready is called?
    }
  });
})(jQuery);
I can override foo's onready event:
foo.onready = function() { alert('bar'); }
But I don't want to override it, I want to extend it so that I'll see both alerts when foo is ready.
Thanks in advance!