[英]How to source code in this
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'
有哪些方法可以恢复indexOf
的功能?
console.log(a.indexOf("two")); // output = 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.