9.5.1 The instanceof operator
The instanceof operator was described in §4.9.4 . The left-hand operand should be the object whose class is being tested, and the right-hand operand should be a constructor function that names a class. The expression o instanceof cevaluates to trueif oinherits from c.prototype. The inheritance need not be direct. If o inherits from an object that inherits from an object that inherits from c.prototype, the expression will still evaluate to true.
As noted earlier in this chapter, constructors act as the public identity of classes, but prototypes are the fundamental identity. Despite the use of a constructor function with instanceof, this operator is really testing what an object inherits from, not what constructor was used to create it.
If you want to test the prototype chain of an object for a specific prototype object and do not want to use the constructor function as an intermediary, you can use the isPrototypeOf()method. For example, we could test whether an object rwas a member of the range class defined in Example 9-1 with this code:
range.methods.isPrototypeOf(r); // range.methods is the prototype object.