Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AddEventListener在IE 11中调用对象无效_Javascript_Internet Explorer 11 - Fatal编程技术网

Javascript AddEventListener在IE 11中调用对象无效

Javascript AddEventListener在IE 11中调用对象无效,javascript,internet-explorer-11,Javascript,Internet Explorer 11,我有以下代码片段,其中我尝试实现addEventListener的自定义行为: var original = Element.prototype.addEventListener; Element.prototype.addEventListener = function(type, listener, options) { original(type, listener, options); // throws an error }; document.body.addEventL

我有以下代码片段,其中我尝试实现addEventListener的自定义行为:

var original = Element.prototype.addEventListener;

Element.prototype.addEventListener = function(type, listener, options) {
    original(type, listener, options); // throws an error
};

document.body.addEventListener('click', function(){});
该代码在Chrome和Firefox上正常工作,但在IE11下,它通过以下错误运行:“SCRIPT65535:无效调用对象”。以下代码真的可以在IE中完成吗?还是我遗漏了什么

var original = document.addEventListener;

Element.prototype.addEventListener = function(type, listener, options) {
    original.bind(document, type, listener, options)();
};

document.body.addEventListener('click', function(){});
老实说,我不完全理解这种情况,但显然与函数的绑定有关。我遇到了类似的情况,并以类似的方式解决了它。在研究过程中,我遇到了这样一个问题。对不起,我来晚了一点。:-)

如果有人能准确地解释这里发生了什么,那就太好了