如果检测到某个浏览器,我该如何删除某个功能? 这是功能和检测:
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/