Re:ECMAScript for XML - Direct XML Syntax in ECMAScript
by olliej on Wednesday June 02, 2021 @09:25PM
(#27376126)
Sigh. As the person who came up with for(of) I can say that's not the reason.
for(in) existed in JS, and the semantics were never going to be changed, that wasn't something that was on the table or was ever considered.
However other languages have syntaxes like:
for each (...)
foreach (...)
for ( .. : .. )
All of which would be more consistent and wouldn't require a non-reserved word be reserved in one context.We couldn't use `foreach` or `for each` as they conflicted with e4x - one directly, the other by being sufficiently similar to not be plausible.
More depressingly for(:) was killed because of the zombie "typed JS" proposal.
Unless you were hoping for an entirely new keyword such as foreach (like C#'s foreach(in)), and in that case yes they couldn't do that because ES3 settled on a Reserved Keyword list and they didn't want to break ES3 compatibility either. While ES3 attempted forward compatibility by including some keywords related to E4X (and ES4's type system), the list of keywords they came up with in ES3 wasn't "because" of E4X. (It was because of "strict mode" and defining what "strict" meant as rather, er, strictly as possible.)