class

  // 手机
      // function Phone(brand,price){
      //   this.brand = brand;
      //   this.price = price; 
      // }

      // // 添加方法
      // Phone.prototype.call = function(){
      //   console.log('可以打电话');
      // }

      // //实例化对象
      // let Huawei = new Phone('华为',5999);
      // Huawei.call();
      // console.log(Huawei);


      // class  
      class Phone{
        // 构造方法 new 的时候会自动执行
        constructor(brand,price){
          this.brand = brand;
          this.price = price; 
        }

        // 方法必须使用这种写法 不能使用es5 的对象完整形式
        call(){
          console.log('可以打电话');
        }

      }

      let onePlue = new Phone('1+',1999); 
      onePlue.call();
      console.log(onePlue);
posted @ 2021-05-18 22:32  13522679763-任国强  阅读(31)  评论(0)    收藏  举报