• 构造函数中没有显示的创建Object对象, 实际上后台自动创建了

  • 直接给this对象赋值属性和方法, this即指向创建的对象

  • 没有return返回值, 后台自动返回了该对象

     2     function Student(name,age,sex){
     3         //var this = {}
     4         this.name = name;
     5         this.age = age;
     6         this.sex = sex;
     7         this.say = function(){
     8             console.log(this.name);
     9         }
    10         //return this//没有返回则自动返回
    11     }
    12     
    13     var student  = new Student('zhangsan',13,'male');
    14     student.say();//zhangsan

     

相关文章:

  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-09-23
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案