Александр Ефремов (2018-02-21T05:06:31.000Z)
> 20 февр. 2018 г., в 22:05, Mike Samuel <mikesamuel at gmail.com> написал(а):
> 
> 
> 
> On Tue, Feb 20, 2018 at 12:33 PM, Александр Ефремов <mr.efrem at gmail.com <mailto: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.
> 

I took this behavior it from `Symbol.hasInstance` use cases: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance>
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: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180221/42a89615/attachment.html>
mr.efrem at gmail.com (2018-02-21T05:16:47.053Z)
> 20 февр. 2018 г., в 22:05, Mike Samuel <mikesamuel at gmail.com> написал(а):
> 
> 
> 
> On Tue, Feb 20, 2018 at 12:33 PM, Александр Ефремов <mr.efrem at gmail.com <mailto: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.
> 

I took this behavior from `Symbol.hasInstance` use cases: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance>

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 -:).