Static variables in JavaScript

后端 未结 30 2231
别那么骄傲
别那么骄傲 2020-11-22 01:55

How can I create static variables in Javascript?

30条回答
  •  醉话见心
    2020-11-22 02:43

    function Person(){
      if(Person.count == undefined){
        Person.count = 1;
      }
      else{
        Person.count ++;
      }
      console.log(Person.count);
    }
    
    var p1 = new Person();
    var p2 = new Person();
    var p3 = new Person();
    

提交回复
热议问题