This commit is contained in:
Ilya Kantor 2016-11-22 11:58:58 +03:00
parent 63f55dc65d
commit 83b93e5992
49 changed files with 699 additions and 281 deletions

View file

@ -1,7 +1,7 @@
Да, это выглядит достаточно странно, поскольку объект `a` не создавался функцией `B`.
Yeah, looks strange indeed.
Но методу `instanceof` на самом деле вообще не важна функция. Он смотрит на её `prototype` и сверяет его с цепочкой `__proto__` объекта.
But `instanceof` does not care about the function, but rather about its `prototype`, that it matches against the prototype chain.
В данном случае `a.__proto__ == B.prototype`, поэтому `instanceof` возвращает `true`.
And here `a.__proto__ == B.prototype`, so `instanceof` returns `true`.
По логике `instanceof` именно прототип задаёт "тип объекта", поэтому `instanceof` работает именно так.
So, by the logic of `instanceof`, the `prototype` actually defines the type, not the constructor function.