primitive boxing in instanceof due to Symbol.hasInstance

Bradley Meck bradley.meck at
Mon Jun 15 18:39:12 UTC 2015

Yes, with regards to O being an Object.

This seems a bit strange to me since things like:

Number.prototype.toString = function () {return 'overriden';}

(1)+'' // "1"

String(1) // "1"

(1).toString() // "overriden"

Implicit string coercion does not box the object.
String constructor does not box the object.

Only the `.` operator which requires an Object boxes the object.

`instanceof` works on non-objects but I think is the only case of an
operator working on both primitives and objects causing boxing.

Is there a reason constructors could/should be allowed to override
`instanceof` for primitives? This just seems odd to have this cause boxing
while `1 instanceof Number` is `false`.

On Mon, Jun 15, 2015 at 12:20 PM, Kevin Smith <zenparsing at> wrote:

>> calls GetMethod on C without checking if it is an Object, this means `1
>> instanceof Foo` could be affected by mutating
>> `Number.prototype[Symbol.hasInstance]`.
> I assume you mean "without checking if O is an object"
>> I am assuming this is unintended?
> IIUC the point of @@hasInstance is to allow the programmer to define
> completely arbitrary semantics for "instanceof" when applied to "C", even
> if C is a built-in.  Do you see a problem with this behavior?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list