Isiah Meadows (2015-02-23T19:59:39.000Z)
On Feb 23, 2015 6:06 AM, "Andrea Giammarchi" <andrea.giammarchi at gmail.com>
wrote:
>
> quick one to whoever will write the proposal: please bear in mind the
empty function **must** have a frozen prototype too
>
> Regards

Andrea, good catch.

>
> On Sun, Feb 22, 2015 at 11:18 PM, Jordan Harband <ljharb at gmail.com> wrote:
>>
>> I'd love to bring a proposal to the committee for this since it seems
like there's interest.
>>
>> I suspect that even though some of the "empties" seem useless to some,
somebody somewhere will find a use case, and consistency is useful (that
everything that could have a concept of "empty" would have a .empty)
>>
>> Errata:
>>  - I don't believe `GeneratorFunction` is a global, so we wouldn't need
to specify one of those

I actually forgot about that... Makes no sense to me why there isn't one in
the first place. Maybe an oversight in ES6? (could probably be put on track
for ES7 easily, simply requiring that the string argument represents the
source code for a GeneratorBody). Probably better suited to a separate
proposal, though. I can write a more accurate prollyfill later today.

>>  - I wonder if `Promise.empty` as `new Promise()`, ie, a forever pending
promise, would make sense?

Maybe a forever-fulfilled one? Although there are probably use cases for
all three kinds, pending, fulfilled, and rejected. Maybe all three would be
better than a simple 'empty' one.

>>  - or `Date.empty` as `new Date(0)`?

That could work.

>>  - We'd definitely want `Map.empty` and `Set.empty` assuming
`Object.freeze` actually froze them

Object.freeze does not freeze them, as far as I know. It might require
method overrides.

>>  - We'd probably want
`Object.freeze(Object.seal(Object.preventExtensions(empty)))`, to be extra
restrictive.

Doesn't Object.freeze imply the other two? I thought it did.

>>
>> Does anyone see any problems or have any objections, beyond "I don't
think there's a use case"?
>>
>> On Sun, Feb 22, 2015 at 2:58 PM, Isiah Meadows <isiahmeadows at gmail.com>
wrote:
>>>
>>> I really liked Jordan Harband's suggestion of adding Array.empty,
Function.empty, etc. to ES7. It is relatively easy to polyfill as well.
>>>
>>> ```js
>>> [Array,
>>>  ArrayBuffer,
>>>  Int8Array,
>>>  Int16Array,
>>>  Int32Array,
>>>  Uint8Array,
>>>  Uint8ClampedArray,
>>>  Uint16Array,
>>>  Uint32Array,
>>>  Float32Array,
>>>  Float64Array]
>>> .map(T => [T, new T(0)])
>>> .concat([
>>>   [Object, {}],
>>>   [String, ''],
>>>   [RegExp, /(?:)/],
>>>   [Function, function () {}],
>>>   [GeneratorFunction, function* () {}]
>>> ])
>>> .forEach(([root, empty]) =>
>>>   Object.defineProperty(root, 'empty', {
>>>     value: Object.freeze(empty),
>>>     configurable: true,
>>>     enumerable: false,
>>>     writable: false
>>>   }));
>>> ```
>>>
>>> The code effectively explains what I think would make suitable
replacements for each. I don't see the use cases for some of these, though,
such as `String.empty` or `RegExp.empty`.
>>>
>>> --
>>> Isiah Meadows
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>>
>> _______________________________________________
>> 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/20150223/9b01669b/attachment.html>
d at domenic.me (2015-03-06T00:40:13.317Z)
Andrea, good catch.