Overriding Map/etc with get/set hooks?

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed May 22 10:52:39 PDT 2013


is simply static collection, so immutable:

```
var all = document.querySelectorAll("*");
var length = all.length;
all[length] = 'whatever';
alert(all.length === length);
[].push.call(all, 'whatever');
alert(all.length === length);
```

you can put properties because is extensible but you won't change the index
nature of that collection neither you can change addressed variables ...

NodeList instances are created like this:

```
function Ecw(value) {
  return {
    enumerable: true,
    writable: false,
    configurable: false,
    value: value
  };
}

Object.defineProperties(
  Object.create(NodeList.prototype),
  {
    "0": Ecw(document.documentElement),
    "1": Ecw(document.head),
    "2": Ecw(document.body),
    "length": Ecw(3)
  }
);
```

this one regardless the returned descriptor info (at least in Chrome) which
is not trustable with hosted natives

regards




On Wed, May 22, 2013 at 10:21 AM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:

> 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.)
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130522/14599207/attachment.html>


More information about the es-discuss mailing list