如何在此源代码

时间:2018-03-06 19:22:11

标签: javascript

indexOf

有哪些方法可以恢复console.log(a.indexOf("two")); // output = 1 的功能?

Format$(Sheet1.Range("A1").Value,"yyyy-mm-dd")

1 个答案:

答案 0 :(得分:1)

您只需重新分配来自Array.prototype的原始函数。

var a = ["one", "two", "three"];
 console.log(a.indexOf("two")); // output = 1

a.indexOf = function(val) {
  return 'HAHAHA';
};

console.log(a.indexOf("two")); // output = 'HAHAHA'

a.indexOf = Array.prototype.indexOf; // re-assign the original function
                                     // which is inherited from Array.prototype.

console.log(a.indexOf("two")); // output = 1