Consider this code:
<input type="button" value="Debugger Test" onclick="debugger;" /> <input type="button" value="Prototype Test" onclick="console.log(__proto__);" />
When you click on the โDebugger Testโ and open your debugger, you will see that there appears to be an implicit with scope wrapped around onclick , which makes all the <input> properties available without having to reference the button.
Clicking on the "Prototype Test" will register the prototype of the current area. You will see that this is an HTMLInputElement prototype, which makes all the properties available for defining this entire prototype chain available to the scope.
It is interesting to note that the included prototype portion of the current HTMLDocument chain HTMLDocument also included.
All this means that all global attributes ( lang is one of them) and some others, specific to buttons, are redefined. For example. value , type will not work either. Similarly, variables such as createElement (from document ) will not work either, but an non-copyable append (from ParentNode.prototype ) will.
All of this is also explained in this answer to a related question about global variables that conflict with window properties.
It is best to use the standard way to add event listeners: addEventListener .
<input type="button" value="Test" /> <script> function lang() { alert("Hello, World! Its not an HTML event handler attribute this time"); } document.querySelector("input").addEventListener("click", lang); </script>
Sebastian simon
source share