Polymer: [Suggestion] for-of instead of for-loop

Created on 22 Mar 2018  路  4Comments  路  Source: Polymer/polymer

Would it be a good idea if Polymer adopted for-of instead of for-loop to iterate over arrays? Babel offers a plugin to convert it harmoniously without using iterators.

2.x api-feedback p3

Most helpful comment

@sorvell, as mentioned above:

Babel offers a plugin to convert it harmoniously without using iterators.

Please, check here.

All 4 comments

I am okay with these changes, although I have two comments:

  1. Are there any performance characteristics associated with this change? We do not want to regress in terms of performance
  2. Rather than doing this all at once, I propose we change these loops whenever we are changing the file anyways, to avoid cluttering our git history

for-of brings good features:

  • Iteration over array-like (HTMLCollection, NodeList, Arguments), iterators and generators.
  • Faster than Array#forEach
  • DRY/Readability
  • Async iteration
  • Can be compiled to for-loop, keeping all theses features and the performance as it is.

Thanks for the suggestion. We love using for-of in application code, but within the library itself we generally manually iterate lists.

We do this for speed and to avoid the extra compiled code. For example, a simple for-of balloons to 25 lines using babel.

@sorvell, as mentioned above:

Babel offers a plugin to convert it harmoniously without using iterators.

Please, check here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SergRZ picture SergRZ  路  3Comments

ghost picture ghost  路  4Comments

limonte picture limonte  路  3Comments

bmodeprogrammer picture bmodeprogrammer  路  3Comments

abdonrd picture abdonrd  路  4Comments