gpt4 book ai didi

javascript - 如何获取此中的源代码

转载 作者:行者123 更新时间:2023-12-03 02:21:29 25 4
gpt4 key购买 nike

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

关于javascript - 如何获取此中的源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49138458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com