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

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("=====");

10-06 12:27