Error in IE when manually calling event handler, given certain conditions

前端 未结 3 715
不知归路
不知归路 2021-01-31 11:25

Preface

  • Please note, I\'m not looking for a code solution, but rather insight into why this may occur.
  • The error occurs in IE (tested 7 & 8), but no
3条回答
  •  鱼传尺愫
    2021-01-31 12:15

    As to "why" it was implemented this way, there's probably no answer from the outside. A good example is when former IE developer, the inventor of innerHTML, faces problems with innerHTML itself.

    Asking why is also unnecessary because

    1. You don't often call event handlers with parameters explicitly
    2. You can work around the issue (as you stated in your question)

    Another thing to note is that your analogy is too specific. The issue is not restricted to the assignment expression, you can reproduce it with other types of expressions:

    undefined === elem.onclick( true )
    typeof elem.onclick( true )
    elem.onclick( true ) - 1
    alert(elem.onclick( true ))
    

提交回复
热议问题