实例对象与静态成员

204 阅读1分钟

我们知道实例对象就是内部用this添加的对象,只能通过实例化来访问,不可以通过实例化对象来访问,而在构造函数本身上添加的成员时静态成员,只能通过构造函数来访问,不能通过对象来访问

```function Star(){
      this.uname=uname;
      this.age=age
      this.sing=function(){
      console.log('唱跳全能')
      }
   }
   var star=new Star('明星',18);
   console.log(star.uname);//明星
   console.log(Star.uname);//undefined
   Star.sex='未知';
   console.log(Star.sex);//未知
   console.log(star.sex);//undefined