classes: remove patterns

This commit is contained in:
Ilya Kantor 2019-04-21 13:40:15 +03:00
parent be9f48c2f2
commit b8eb04dfb6
76 changed files with 429 additions and 743 deletions

View file

@ -0,0 +1,7 @@
Yeah, looks strange indeed.
But `instanceof` does not care about the function, but rather about its `prototype`, that it matches against the prototype chain.
And here `a.__proto__ == B.prototype`, so `instanceof` returns `true`.
So, by the logic of `instanceof`, the `prototype` actually defines the type, not the constructor function.

View file

@ -0,0 +1,20 @@
importance: 5
---
# Strange instanceof
Why `instanceof` below returns `true`? We can easily see that `a` is not created by `B()`.
```js run
function A() {}
function B() {}
A.prototype = B.prototype = {};
let a = new A();
*!*
alert( a instanceof B ); // true
*/!*
```