Symbol.hasInstance and [[Get]] vs [[GetOwnProperty]]

Jordan Harband ljharb at gmail.com
Wed Aug 24 21:20:13 UTC 2016


All inheritance in JS stops a prototype chain lookup if an own property
exists, no matter the value (iow, including undefined) - so this is fully
consistent with JS inheritance.

On Wed, Aug 24, 2016 at 10:38 AM, /#!/JoePea <joe at trusktr.io> wrote:

> Well, after looking at "Runtime Semantics: InstanceofOperator(O, C)" in
> the spec that you linked to, the mere fact that `@@hasInstance` can be
> undefined in which case inheritance is ignored completely goes against...
> inheritance.
>
> So, this proves that we can make the spec be anything we wish it to be (as
> currently it doesn't follow pure prototypal inheritance), so we could
> easily choose to use `[[GetOwnProperty]]` without inheritance if we wanted
> to, and in my opinion that is much better.
>
> */#!/*JoePea
>
> On Tue, Aug 23, 2016 at 10:59 PM, Claude Pache <claude.pache at gmail.com>
> wrote:
>
>> ```js
>> Uncaught TypeError: Cannot read property 'call' of undefined
>> ```
>>
>>
>> (...)
>>
>>
>> Also, reading the message of your TypeError, I wonder if Babel may also
>> fail unexpectedly in case SomeClass does not inherit the standard
>> `Function#call`, as in: ```class SomeClass { static call() { throw "Pwnd!"
>> } }```.
>>
>>
>> Correction: The potential issue I was thinking of, is when
>> `SomeClass[Symbol.hasInstance]` does not inherit the standard
>> `Function#call`:
>>
>> ```js
>> class SomeClass {
>>     static [Symbol.hasInstance]() { /* foo */ }
>> }
>> SomeClass[Symbol.hasInstance].call = function () { throw "Pwnd!" }
>> ```
>>
>> which is quite a corner case.
>>
>> —Claude
>>
>>
>>
>
> _______________________________________________
> 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/20160824/ebdacfc9/attachment.html>


More information about the es-discuss mailing list