Just to clarify apply is a native javascript function implemented in
1.3
the second parameter isnt actually needed (its for defining arguments)

anyway i decided to jquerify it and ended with this:

(function ($) {
  $.extend($.fn, {
    apply :function (fn, args) {
      return this.each(function () {
        fn.apply(this, args);
      });
    }
  });
})(jQuery);

now it can be called like so:

$('#example').apply(function () {
  alert(this.id);
});

$('#example').apply(function (a, b) {
  alert(a + " : " + b); // "foo : bar"
}, ['foo', 'bar']);

Reply via email to