Proposal to add symbol: "hasInstanceStrict"

Александр Ефремов mr.efrem at
Wed Feb 21 05:06:31 UTC 2018

> 20 февр. 2018 г., в 22:05, Mike Samuel <mikesamuel at> написал(а):
> On Tue, Feb 20, 2018 at 12:33 PM, Александр Ефремов <mr.efrem at <mailto:mr.efrem at>> wrote:
> Anyone else has interes to this proposal?
> I'm probably just going to echo themes that T.J. has dealt with better, but:
> Things i like:
> - provides preconditions
> - guards locals
> Things I don't like:
> - doesn't deal with postconditions
> - somewhat redundant with annotations
> - adds syntax
> It seems that there are two separable issues:
> 1. Defining guards
> 2. Syntax for specifying guards.
> It seems to me that (2) might be doable with annotations for locals,
> so deploying guards could build on annotations.
> Where your proposal shines, is in a definition of a guard.
> I don't much like the way the definition is tied to classes though.
> Maybe, for
>   class C {}
> make
>   C(x)  // [[Call]] not [[Construct]]
> default to (x instanceof this) unless the static property you propose is defined.

I took this behavior it from `Symbol.hasInstance` use cases: <>
and how me seems here would be similar approach, because I also wanted to check that assignable value is instance of certain class. But otherwise it must to throw the `TypeError` exception.
And I didn’t understand what you mean about `x instanceof this`.

> That would allow you to use any function type as a value predicate which is the
> minimum needed for a guard.
> Leave sub-types that don't override [hasInstance] from super-types to linters.

Here thought I also didn’t understand.

> If confusion between (new C(x)) and (C(x)) is too much of a hazard, maybe
> adjust the calling convention for guards so that they always receive a well-known
> symbol as the first argument, so can switch between acting as a predicate and
> telling developers how to create class instances.

And here -:). 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list