9.5 Classes and Types
9.5 Classes and Types | 209
classof() function of Example 6-4 . But when we define our own classes using the techniques shown in this chapter, the instance objects always have a class attribute of “Object”, so the classof() function doesn’t help here.
The subsections that follow explain three techniques for determining the class of an arbitrary object: the instanceof operator, the constructor property, and the name of the constructor function. None of these techniques is entirely satisfactory, however, and the section concludes with a discussion of duck-typing, a programming philosophy that focuses on what an object can do (what methods it has) rather than what its class is.欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/27676.html