[英]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.