Proposal to add symbol: "hasInstanceStrict"
Michał Wadas
michalwadas at gmail.com
Sun Feb 18 16:56:33 UTC 2018
Runtime type checking isn't widely deployed for many reasons. Programmable
runtime type checking would be even worse because engine can't just throw
away function call (only extreme minority of JS function can be proven to
be pure).
On 18 Feb 2018 5:30 pm, "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/20180218/9a9071d0/attachment-0001.html>
More information about the es-discuss
mailing list