Determine if a value is Callable/Constructible

classic Classic list List threaded Threaded
43 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Determine if a value is Callable/Constructible

Kevin Smith

That distinction means that you can’t “really” [[Call]] a constructor, it’s just that the reason is slightly different from trying to [[Call]] an Array instance (or something)

Another way to look at the situation is that, by default, calling a class constructor will throw an error.  That default may be changed however.  Just not with ES6 : ) 


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Determine if a value is Callable/Constructible

Boris Zbarsky
In reply to this post by Axel Rauschmayer
On 3/30/15 1:33 PM, Axel Rauschmayer wrote:
> As in “makes sense to call”. In the past, `typeof x === 'function'” was
> an adequate test for checking whether it makes sense to call `x`.

Except for all the DOM constructors, right?

-Boris
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Determine if a value is Callable/Constructible

Peter Flannery
In reply to this post by Caitlin Potter
I personally think it's better to have **harmony** between ES5 and ES6
classes and not incompatibility.
The web and the like are currently littered with applications that use
[[call]] as a sub classing technique and now all these apps will be
give a harsh choice, either disregard using ES6 class syntax,
completely overhaul to suit ES6 or just don't move to ES6 until
time\money budgets permit.

Is it not possible to:

1. Have a unified construct for both class and function syntax, i.e.
`SomeClass.constructor.call` can be used to sub class for both ES6 and
ES6
2. Instead of throwing the message `Class constructors cannot be
invoked without 'new'` **change it to become** `Class constructors
cannot be invoked without using 'new' or it's .constructor method`
3. Functions will continue to have [[call]] regardless but it should
still be recommended to use `SomeClass.constructor.call` for sub
classing for great compatibility
4. Polyfill vendors have their own spec for this scenario. i.e. when
the detect class syntax is used then mark the output ES5 prototype
with a [[class-tag]] that allows them to assert and throw the same
`Class constructors cannot be invoked.....` message as stated in point
2 above
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
123