9.2.1 Constructors and Class Identity
As we’ve seen, the prototype object is fundamental to the identity of a class: two objects are instances of the same class if and only if they inherit from the same prototype object. The constructor function that initializes the state of a new object is not fundamental: two constructor functions may have prototype properties that point to the same prototype object. Then both constructors can be used to create instances of the same class.
Even through constructors are not as fundamental as prototypes, the constructor serves as the public face of a class. Most obviously, the name of the constructor function is usually adopted as the name of the class. We say, for example, that the Range() constructor creates Range objects. More fundamentally, however, constructors are used with the instanceofoperator when testing objects for membership in a class. If we have an object r and want to know if it is a Range object, we can write:
r instanceof Range // returns true if r inherits from Range.prototype欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/31375.html