作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图理解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/
我是一名优秀的程序员,十分优秀!