What is the correct way to create a Javascript class?

后端 未结 4 1455
情深已故
情深已故 2021-02-14 20:14

I\'m trying to figure out how to construct my Javascript classes (or singleton objects) correctly.

var obj = new Object();
obj.foo = \'bar\';
obj.method = functi         


        
4条回答
  •  遥遥无期
    2021-02-14 20:28

    you can also use something like:

    function O(x,y) {
       this.x=x;
       this.y=y;
       this.method=function() {...}
       return this;
    }
    
    var o=new O(0,0);
    

提交回复
热议问题