gpt4 book ai didi

javascript - 如何删除/删除 JavaScript function()?

转载 作者:行者123 更新时间:2023-11-30 11:10:10 24 4
gpt4 key购买 nike

如果检测到某个浏览器,我该如何删除某个功能?这是功能和检测:

function parallaxIt(e, target, movement) {
var $this = $("#app");
var relX = e.pageX - $this.offset().left;
var relY = e.pageY - $this.offset().top;

TweenMax.to(target, 1, {
x: (relX - $this.width() / 2) / $this.width() * movement,
y: (relY - $this.height() / 2) / $this.height() * movement,
z: 0.01,
rotation:0.01
});
}


var version = detectIE();
if (version === false) {
//Do Nothing
} else if (version >= 12) {
//Remove Function
} else {
$("#iefix").attr({href : "/static/css/app-iefix.css"});
//Remove Function
}

因此,当检测到任何 IE 时,我想删除函数 parallaxIt() 或破坏它,这样它就不起作用了?亲切的问候

(代码的检测部分显然是完整代码的一小段,因此您更容易阅读而不是阅读完整代码)

最佳答案

至少对我来说,在 Chrome v71 (Windows 10) 中,删除该功能没有任何作用(它保持存在)。但是您可以重新分配它成为一个空操作函数:

function parallaxIT() {
console.log("inside parallaxIT");
}

// delete
delete window.parallaxIT;
console.log("parallaxIT was 'deleted', does it still show output:");
parallaxIT();

console.log("=====");

// re-assign
window.parallaxIT = function() {} // no-op function
console.log("parallaxIT was re-assigned, does it still show output:");
parallaxIT();

console.log("=====");

关于javascript - 如何删除/删除 JavaScript function()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54006691/

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