Javascript AddEventListener在IE 11中调用对象无效
我有以下代码片段,其中我尝试实现addEventListener的自定义行为: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
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(){});
老实说,我不完全理解这种情况,但显然与函数的绑定有关。我遇到了类似的情况,并以类似的方式解决了它。在研究过程中,我遇到了这样一个问题。对不起,我来晚了一点。:-)
如果有人能准确地解释这里发生了什么,那就太好了