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

后端 未结 3 697
醉酒成梦
醉酒成梦 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:39

    MyClass.prototype.method1: function () {/**/};

    Correction to the above: it should be

    MyClass.prototype.method1 = function () {/**/}; 
    

    (Note the equals sign after 'method1').

    The colon is used only when the method definition is itself within an object definition, like:

    var myObject = {myVar1: 10, myMethod1: function() { /* */};
    

提交回复
热议问题