instanceof Operator

liorean liorean at
Sun Oct 21 10:22:32 PDT 2007

On 21/10/2007, Eugen.Konkov at <Eugen.Konkov at> wrote:
> Does instanceof operator check 'constructor' property in [proto] chain?

No. It uses the [[HasInstance]] private method of the object passed in
as the right operand.

In the case of

    'string' instanceof String;

F is String and 'string' is V in the following algorithm:
~~~~~~~~ [[HasInstance]] (V)
Assume F is a Function object.
When the [[HasInstance]] method of F is called with value V, the
following steps are taken:
1. If V is not an object, return false.
2. Call the [[Get]] method of F with property name "prototype".
3. Let O be Result(2).
4. If O is not an object, throw a TypeError exception.
5. Let V be the value of the [[Prototype]] property of V.
6. If V is null, return false.
7. If O and V refer to the same object or if they refer to objects
joined to each other (section 13.1.2), return true.
8. Go to step 5.
David "liorean" Andersson

More information about the Es4-discuss mailing list