Overriding Map/etc with get/set hooks?

Domenic Denicola domenic at domenicdenicola.com
Wed May 22 10:21:05 PDT 2013


From: Tab Atkins Jr. [jackalmage at gmail.com]

> NodeList is an interesting case, actually.  It's an Array, but with a type restriction.

What do you mean by that? Surely you don't mean "can only store nodes":

```
> var nodeList = document.querySelectorAll("div");
undefined

> nodeList.length
22

> nodeList[22] = "not a node";
"not a node"

> nodeList[22]
"not a node"
```

On the other hand, not sure what's going on here:

```
> nodeList[1] = "not a node either";
"not a node either"

> nodeList[1]
<div class=​"banner">​…​</div>​

> Object.getOwnPropertyDescriptor(nodeList, "1")
Object {value: div.banner, writable: true, enumerable: true, configurable: true}
```

(both results in Chrome 27. Firefox 21 has a different pathology... It returns `undefined` for `nodeList[22]`, although `Object.isExtensible(nodeList) === true`. But it gets the second case right, giving `writable: false` to correctly reflect the behavior there.)


More information about the es-discuss mailing list