AddEventListener () as a global function

I'm just confused. assuming that I am implementing addEventListener()as a global function (as opposed to the method of a specific node, similar node.addEventListener()), then it acts the same as a regular global function, or something goes under the hood, while the code ends the method some specific node

Note. The DOM 2 level defined by addEVentListener provides that the handler registers with node. so that node it is registered; The window object is not a node

+6
source share
1 answer

It will be applied to the global object window(which has the function addEventListener). Because:

var a = 5;

console.log(a);
console.log(window.a);
Run codeHide result

Thus:

addEventListener( ... );

these are the same things if you use:

window.addEventListener( ... );
+7
source

Source: https://habr.com/ru/post/1016696/


All Articles