3 ms·
Dynamic keys (square brackets on the left hand side in an object literal) have been around for nearly 10 years, if memory serves. https://www.samanthaming.com/
by zdragnar 1y ago
Dynamic keys (square brackets on the left hand side in an object literal) have been around for nearly 10 years, if memory serves.
https://www.samanthaming.com/tidbits/37-dynamic-property-name-with-es6/ https://www.samanthaming.com/tidbits/37-dynamic-property-nam...
Also in the example is method shorthand:
https://www.samanthaming.com/tidbits/5-concise-method-syntax/ https://www.samanthaming.com/tidbits/5-concise-method-syntax...
Since symbols cannot be referred to by strings, you can combine the two.
Basically, there isn't any new syntax here.
- a4isms 1y agoYes, this will be familiar to people creating objects or classes that are intended to represent iterable collections. You do the same dynamic key syntax with a class declaration or object literal, but use `Symbol.iterator` as the well-known symbol for the method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...