Difference between MyClass.prototype = new Object() and MyClass.prototype = Object

后端 未结 3 699
醉酒成梦
醉酒成梦 2021-02-05 21:51

could anyone please tell me, where in Javascript the difference between

MyClass.prototype = new Object(); //or ... = {}

and

MyC         


        
3条回答
  •  太阳男子
    2021-02-05 22:33

    It depends on Object. If it is a function you want to use the new Object() method. If it is a "virtual class" (defined using Object = {someProperty: someValue}) then you use the second method.

    Some more pointers in this page on prototype inheritance in JavaScript

提交回复
热议问题