playcanvas / pcui

UI component library for web-based tools
http://playcanvas.github.io/pcui
MIT License
664 stars 62 forks source link

Refactor accessing of childNodes array #301

Closed willeastcott closed 1 year ago

willeastcott commented 1 year ago

This PR:

slimbuck commented 1 year ago

Why prefer for of to forEach?

willeastcott commented 1 year ago

@slimbuck I'll admit this is a personal preference when I am stepping through a loop. With forEach, you have to set a breakpoint in the function, but with for...of, you can just single step through loop iterations. So yeah, I just generally prefer to use for...of where it can be.

willeastcott commented 1 year ago

And also worth mentioning that forEach is worse for performance than for...of. See:

https://leanylabs.com/blog/js-forEach-map-reduce-vs-for-for_of/