I want to override jQuery.find to override extra functionality. I have used the idea discussed on Ben Nadel’s blog to do so ( http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm ) but for some reason it doesn’t work for $.find(), this is my code
(function () {
// Store a reference to the original remove method.
var originalFindFunction = jQuery.find;
// Define overriding method.
jQuery.find = function () {
// Log that we are calling the overridden function.
Console.log("------> Find method called");
// then execute the original method
var results = originalFindFunction.apply(this, arguments);
return results;
};
})();
do you have an idea what’s wrong, or how can I override a jquery function?
The demonstration in your reference uses a function from
.fn.Where you’re overriding a function on
Overriding functions on this level have different meaning for
this.When you’re working on
.fn.– the this is the returned query result, which are “mixed in” to any query result.Here, the
thiswill be the root object itself, and the usage by it is different. These are functions or utility functions that are invoked “statically”.