You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pre id="log"></pre>
<script>
function log(msg) { document.getElementById('log').textContent += msg + '\n'; }
function Base() {}
function Derived() {}
Derived.prototype = Object.create(Base.prototype); // OPTIONAL
log(new Base() instanceof Derived); // correctly logs 'false'
Reflect.construct(Base, [], Derived);
log(new Base() instanceof Derived); // from now on, logs 'true'!
</script>
This bug is pretty elusive - if you ever open the developer tools (even just for a second) everything goes back to normal, and the Base constructor again constructs Base objects (hence the HTML logging).
It's also irrelevant whether Derived is a prototypal subclass of Base. Fun fact: if the Object.create call is left out, then in the broken state, new Base() instanceof Base actually returns false!
This seems to be a one-way switch: calling Reflect.construct(Base, [], Other) afterwards does not switch new Base() from creating Deriveds to creating Others. But it also doesn't work to try to workaround the issue with a proactive Reflect.construct(Base, [], Base), since a future call to Reflect.construct(Base, [], Derived) will still cause problems.
EDIT: Also, this bug only triggers if the base class has been instantiated at least once before calling Reflect.construct: so if the first log statement is removed then the second one logs 'false'.
The text was updated successfully, but these errors were encountered:
Repro:
This bug is pretty elusive - if you ever open the developer tools (even just for a second) everything goes back to normal, and the
Base
constructor again constructsBase
objects (hence the HTML logging).It's also irrelevant whether
Derived
is a prototypal subclass ofBase
. Fun fact: if theObject.create
call is left out, then in the broken state,new Base() instanceof Base
actually returns false!This seems to be a one-way switch: calling
Reflect.construct(Base, [], Other)
afterwards does not switchnew Base()
from creatingDerived
s to creatingOther
s. But it also doesn't work to try to workaround the issue with a proactiveReflect.construct(Base, [], Base)
, since a future call toReflect.construct(Base, [], Derived)
will still cause problems.EDIT: Also, this bug only triggers if the base class has been instantiated at least once before calling
Reflect.construct
: so if the first log statement is removed then the second one logs 'false'.The text was updated successfully, but these errors were encountered: