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定义类、实例化,函数的调用方法。

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-06-20
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2021-09-11
  • 2021-05-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
相关资源
相似解决方案