In a very common code example when delegating a Javascript event https://javascript.info/event-delegation, I am confused by where the βmenuβ variable comes from on line 40 in http://plnkr.co/edit/91Q9jINXlue2fXiB0fAY?p=preview . The variable is passed to the constructor, but never initialized. It seems the "menu" variable is automatically created from this div element:
<div id="menu">...</div>
<script>
...
new Menu(menu); /* Who initializes "menu".
...
</script>
I have been doing Javascript for a long time, but it really confuses me. I am also not sure how to generalize this question.
Normally I would do document.getElementById ("menu") to get the div element. Where are these variables initialized and how can I learn more about such variables? Is there a specification?
source
share