From 47d8baceeea1f4146f6edb1b83f6420a79825996 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 18 Jun 2024 17:58:34 -0600 Subject: [PATCH] Normative Conventions: pretend Strings aren't iterable --- normative-conventions.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/normative-conventions.md b/normative-conventions.md index cd55a78..959d744 100644 --- a/normative-conventions.md +++ b/normative-conventions.md @@ -37,3 +37,11 @@ For the purposes of this guideline `-0` is considered to be an integral number ( Some APIs intentionally round non-integral inputs, for example as an attempt to provide a best-effort behavior, rather than because the API fundamentally only makes sense with integers. This guideline does not apply to those cases. NB: This convention is new as of 2024, and most earlier parts of the language do not follow it. + +## Reject primitive Strings in iterable-taking APIs and syntax + +Any time an iterable value (a value that has a `Symbol.iterator` method) is expected, primitive Strings should be treated as if they were not iterable. Usually, this will mean throwing a `TypeError`. String Objects, however, should be treated like any other Object. + +Although primitive Strings are iterable (`String.prototype` has a `Symbol.iterator` method which enumerates code points), it is now considered a mistake to iterate a String without specifying whether the String is providing an abstraction over code units, code points, grapheme clusters, or something else. + +NB: This convention is new as of 2024, and most earlier parts of the language do not follow it.