Reputation: 23921
I am trying to understand this javascript code, which extends jquery. I know calling extend on the jquery object will add a tablesorter object to the $ object.
I want to clear the cache on a tablesorter object, something like this
$("#myTable").tablesorter();
$("#myTable").buildParserCache(); //so as to clear the cache. I get undefined is not a function.
$("#myTable").tablesorter().buildParserCache() //also get undefined is not a function
Can someone explain why this is not possible and how to clear the cache. I know I am butting up against some JS design patterns and scope rules and I would like to understand them.
(function ($) {
$.extend({
tablesorter: new
function () {
var parsers = [],
widgets = [];
this.defaults = {
...
};
/* debuging utils */
function benchmark(s, d) {
log(s + "," + (new Date().getTime() - d.getTime()) + "ms");
}
function buildParserCache(table, $headers) {
if (table.config.debug) {
var parsersDebug = "";
}
Upvotes: 0
Views: 45
Reputation: 37781
The buildParserCache
function is defined inside the function ()
which starts on the fourth line of that snippet, so it will only be accessible outside the function if it is explicitly exposed - and it looks like it isn't, so that is effectively a private function.
The methods which are exposed appear to be grouped after the /* public methods */
comment.
The this.construct = function
function gets further exposed by this:
$.fn.extend({
tablesorter: $.tablesorter.construct
});
so that is the function that ends up being called when $("#myTable").tablesorter()
is called.
Upvotes: 1