Array.isArray(new Proxy([], {})) should be false (Bug 1096753)

Domenic Denicola d at domenic.me
Fri Nov 14 04:53:28 PST 2014


From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Tom Van Cutsem

> Is the `length` invariant really the dominant meaning JS developers attribute to Array.isArray? I think to most developers Array.isArray(obj) returning true means that it's safe to call the array utilities (map, forEach, ...) on obj, not so much that obj.length is special.

This is really interesting. It does argue for some kind of redefinition of Array.isArray to return "is this an instance of some %ArrayPrototype% in some realm?" That is very close to "does the object have an @@isConcatSpreadable" property, the main difference being that you can "fake" the latter via `myObj[Symbol.isConcatSpreadable] = true` while still not inheriting from any %ArrayPrototype%.

---

To me the most interesting question is how to create objects that get JSON-stringified as [], not {}. Some sort of symbol-based mechanism makes sense for that, IMO...



More information about the es-discuss mailing list