1

我一直在处理一些旧的 jsp 页面,并试图将 jQuery 引入其中。然而,这是我在页面上开始使用 jQuery 时得到的结果:

base.js:249 Uncaught TypeError: f is not a function

所以很明显,我们遗留的 base.js 和 jQuery 之间存在冲突。下面是导致问题的 base.js 中的代码片段:

Object.prototype.each = function (f) {
    for (var n = 0; n < this.length; n++)    {
        f (this[n],n);     // This is line 249
    }
    return this;
};

坏消息是我不能轻易地将这个库从页面中重构出来,因为还有一些其他的 JavaScript 库在页面中使用它。

有什么我可以做的吗?谢谢!

4

1 回答 1

2

小建议:

这只是一个黑客工作,解决问题:

Object.prototype.each = function (f) {
  for (var n = 0; n < this.length; n++) {
    if (typeof f == "function")
      f(this[n],n);     // This is line 249
    else
      console.log("You've got a problem here. The f is " + f);
  }
  return this;
};

上面的代码可能会起作用,也可以帮助您调试东西。

于 2016-01-26T18:40:57.823 回答