Maybe it would be less footgunny to support autovivification in a more
class-based way, like Python does?

```javascript
class AutoVivArray extends Array {
  [Symbol.getMissing](identifier) {
    /* if we're here, identifier is not an ownProperty
     * and is nowhere on the prototype chain */
    this[identifier] = new Whatever();
    return this[identifier];
  }
}
```

Though I can't see how that's much more useful than Proxies besides saving
you a little boilerplate

On Fri, Apr 24, 2020 at 3:23 PM Thomas Shinnick <tshin...@gmail.com> wrote:

> You are describing Perl's autovivification feature. Also possible (in
> that syntax) for arrays and mixed object/array chains. I liked it, but many
> saw it as a footgun. There was even a compile time module to turn off the
> feature, if the coder wanted more caution. Having mentioned Perl I will
> assume this is DOA?
>
> On Fri, Apr 24, 2020, 14:36 Tobias Buschor <tobias.busc...@shwups.ch>
> wrote:
>
>> Since we now have the "Optional Chaninig Operator" , perhaps a "Forced
>> Chaining Operator" would also be worth considering.
>> I, personally, could use it:
>>
>>     let table;
>>     table!.user!.id!.type = 'int'
>>
>> will evaluate to:
>>
>>     let table;
>>     if ( ! ( table instanceOf Object) ) table = {};
>>     if ( ! ( table.user instanceOf Object) ) table.user = {};
>>     if ( ! ( table.user.id instanceOf Object) ) table.user.id = {};
>>     table.user.id.type = 'int';
>>
>> Also to be noted:
>> Sometimes a fallback to `Object.create(null)` or something other might be
>> desirable.
>> But since `{}` is syntactical sugar for
>> `Object.create(Object.prototype)`, this would be consistent.
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to