gpt4 book ai didi

javascript - 有没有办法在javascript代码中调用 "benchmark"

转载 作者:行者123 更新时间:2023-12-03 12:11:33 26 4
gpt4 key购买 nike

我试图理解this javascript 代码,扩展了 jquery。我知道打电话extend jquery 对象上将添加一个 tablesorter 对象到 $ 对象。

我想清除表排序器对象上的缓存,如下所示

$("#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

有人可以解释为什么这是不可能的以及如何清除缓存。我知道我遇到了一些 JS 设计模式和范围规则,我想了解它们。

    (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 = "";
}

最佳答案

buildParserCache 函数是在 function () 内部定义的,该函数从该代码段的第四行开始,因此只有在显式声明的情况下才能在函数外部访问它暴露 - 看起来好像没有,所以这实际上是一个私有(private)函数。

公开的方法似乎在 /* publicmethods */ 注释之后分组。

this.construct = function 函数进一步暴露:

$.fn.extend({
tablesorter: $.tablesorter.construct
});

这就是调用 $("#myTable").tablesorter() 时最终调用的函数。

关于javascript - 有没有办法在javascript代码中调用 "benchmark",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com