Proposal to add symbol: "hasInstanceStrict"
Aleksander Efremov
mr.efrem at gmail.com
Mon Feb 19 04:06:38 UTC 2018
If not all understood me. I offer to call that `symbol` only in process of
execution that code. It isn't attempt to create the compiled language -:).
18 февр. 2018 г. 22:04 пользователь "Aleksander Efremov" <mr.efrem at gmail.com>
написал:
> Yes, I think that inherited checks it's also good idea.
> And regading `has` I agree. Maybe better to call `requireInstance`.
>
> 18 февр. 2018 г. 22:03 пользователь "Aleksander Efremov" <
> mr.efrem at gmail.com> написал:
>
>> Yes, I think that inherited checks it's also good idea.
>> And regading `has` I agree. Maybe better to call `requireInstance`.
>>
>> 18 февр. 2018 г. 21:43 пользователь "Mike Samuel" <mikesamuel at gmail.com>
>> написал:
>>
>>> Must hasInstanceStrict's parameter remain untyped for a guard to
>>> complete or is there a top type with an unguarded hasInstanceStrict that
>>> these checks bottom out on?
>>>
>>> "has" to my ear sounds like it should return a boolean. Maybe "require."
>>>
>>>
>>>
>>> On Feb 18, 2018 11:30 AM, "Aleksander Efremov" <mr.efrem at gmail.com>
>>> wrote:
>>>
>>> It’s attempt to provide intermediate layer for implementation of runtime
>>> type checking.
>>>
>>> ```
>>> class PrimitiveNumber {
>>> static [Symbol.hasInstanceStrict](x) {
>>> if (typeof x !== ’number’) {
>>> throw new TypeError(‘Invalid type’);
>>> }
>>> }
>>> }
>>>
>>> function sum(a: PrimitiveNumber, b: PrimitiveNumber) {
>>> return a + b;
>>> }
>>>
>>> const c: PrimitiveNumber = sum(1, 2);
>>> ```
>>>
>>> I.e. when appears assignment of variable (const) if then follows `:
>>> <class>` then JS runtime must to call method `static
>>> [Symbol.hasInstanceStrict](x)` and transfer to there assignable value.
>>>
>>> _______________________________________________
>>> 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/20180219/0c8de5e6/attachment.html>
More information about the es-discuss
mailing list