JavaScript Understanding the need of event delegation -


i read in 1 of articles on web sentence:

adding event handlers each of 1000 cells major performance problem and, potentially, source of browser-crashing memory leaks.

but don't understand it. if example, doing this:

const handler = e => //  document.queryselectorall("td").foreach(td => {    td.addeventlistener("click", handler); }); 

i don't create 1000 functions, use same reference, missing? problem?

i don't create 1000 functions, use same reference, missing?

you still create 1000 function references in 1000 dom nodes. might not seem significant, table grow…

of course, right, if don't create 1000 closures there won't many problems. however, have 1000 buttons same? closures, it's easy let them marginally different things; 1 function need make dynamically depend on cell clicked (the event target). , when you're doing already, go ahead , use single function reference , event delegation…


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -