Re: [heycam/webidl] A new approach to array-ish classes (#796)

In #836 I've started a discussion on some of the details of that particular proposal. In this thread I'll step back a bit and note some features of the current proposal that we might want to rethink.

The main one is that we could do more work to make observable arrays transparently array-like. In particular, right now `ObservableArray` is defined as a class that inherits from `Array`, so:

```js
someObservableArray.constructor !== Array; // it's ObservableArray
someObservableArray.prototype !== Array.prototype; // it's ObservableArray.prototype
```

Additionally, as discussed previously, since this does not meet the definition of "Array exotic object":

```js
Array.isArray(someObservableArray) === false;
```

It's possible to fix all of these, by instead specifying observable arrays a legit JS `Proxy` around an inner `Array` instance. Note that this is different than the current proposal, which uses proxy-like techniques of overriding the internal methods [[GetOwnProperty]], [[Delete]], [[DefineOwnProperty]], etc. We would need to instead literally use the `Proxy` definitions from the 262 spec, including those specific internal methods, [[ProxyTarget]], etc.

The reason for the current approach is that the `ObservableArray`-as-a-distinct-class approach reuses a lot of existing Web IDL machinery. The only things the bindings team would need to do are handling the setters/getters (in a fashion similar to what we envision for FrozenArray anyway, per https://github.com/heycam/webidl/issues/810#issuecomment-538651524), and a [few minor tweaks on top of platform object allocation](https://pr-preview.s3.amazonaws.com/heycam/webidl/pull/836.html#es-ObservableArray-specialness). Whereas, the Proxy-based approach would require writing some fairly custom and intricate bindings code, I believe.

Nevertheless, I'm leaning toward the Proxy-like approach anyway, for priority of constituencies reasons. That would also allow us to remove the constructor (it's just a proxied array; no constructor needed!), and thus defer some of the questions in https://github.com/heycam/webidl/pull/836#issuecomment-578266974.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/796#issuecomment-578273849

Received on Friday, 24 January 2020 19:45:37 UTC