js中使用function定义类、实例化,函数的调用方法

              function Test002(name, age){
                  name,
                  age,
                  this.printInfo = function(){ //定义的公有方法
                      console.log(name, age);
                  }
                  
              }
              let test002 = new Test002("weisheng", 32)
              test002.printInfo()   //打印 weisheng 32
              




function Test003(name, age){ name; age; var printInfo = function(){ console.log(name, age); } } let test003 = new Test003("weisheng", 32) test003.printInfo() //报错,私有方法

 

js中使用function定义类、实例化,函数的调用方法。

posted @ 2021-07-27 21:31  小德cyj  阅读(206)  评论(0编辑  收藏  举报