develwoutacause’s avatardevelwoutacause’s Twitter Archive—№ 1,538

  1. Today's lesson in #WTF #JavaScript: Apparently MyClass.prototype is actually an *instance* of its parent class and passes an instanceof check. It also does *not* invoke the constructor, meaning you can actually instantiate a class *without constructing it*. wat?
    A JavaScript code snippet which defines a Parent class and a Child class which extends it. The Parent class also logs "new parent" in its constructor.

The snippet then logs the output of three expressions.

First, it does `new Child() instanceof Parent)`. This returns `true` and also logs "new parent", reasonable behavior.

Second, it does `Child instanceof Parent`. This returns `false`, also reasonable.

Third, it does `Child.prototype instanceof Parent`. This returns `true` and doesn't log "new parent" at any point. wat?