Proposal to add symbol: "hasInstanceStrict"

Mike Samuel mikesamuel at gmail.com
Tue Feb 20 18:05:05 UTC 2018


On Tue, Feb 20, 2018 at 12:33 PM, Александр Ефремов <mr.efrem at gmail.com>
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.

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.

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180220/b54c2b6e/attachment.html>


More information about the es-discuss mailing list