[Pas2js] for .. in loop
Ryan Joseph
ryan at thealchemistguild.com
Fri May 18 17:46:54 CEST 2018
> On May 18, 2018, at 10:36 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>
> Expectation is the god of many faces.
>
> Keep in mind, that a JS array is still an associated array:
>
> var a = [1,2];
> a.bla = 'foo';
> for (var key in a){
> console.log(a[key]);
> }
>
> gives:
> 1
> 2
> foo
That’s sneaky. But does is kind of non-standard use arrays mean we shouldn’t be able to for..in in all cases? It seems the programmer should be able to tell the compiler “this array is only ints” and get back the result based on that assumption (even if there’s a bug and this isn’t the case during runtime).
Regards,
Ryan Joseph
More information about the Pas2js
mailing list