“Parasitic Combination Inheritance” in Professional JavaScript for Web Developers

后端 未结 2 1735
囚心锁ツ
囚心锁ツ 2020-12-10 16:59

Professional JavaScript for Web Developers, Third Edition by Nicholas C. Zakas (Wrox, 2012, p.210-215 describes \"Parasitic Combination Inheritance\" using the following fun

2条回答
  •  孤街浪徒
    2020-12-10 17:33

    The assignment to "constructor" is not mandatory as the assignment to "prototype" is. The reason to do it is that function prototypes usually come with the "constructor" property set by default. It might be useful for libraries that copy objects since you can get a reference to that object's constructor from the object itself.

    function Foo(){
    }
    
    obj = new Foo();
    
    console.log(obj.constructor); //function Foo
    

提交回复
热议问题