/** * ES6提供了class(类)的概念; * 通过class定义关键字,可以是定义类 * class 定义类 * constructor 定义构造函数初始化 * extends 继承父类 * super 调用父级构造函数方法 * static 定义静态的方法和属性 */ // class定义类 class Phone{ // 构造函数 constructor(brand,color,price){ this.brand = brand; this.color = color; this.price = price; } // 定义方法 call(){ console.log("请给我打电话!") } } // 子类 class newPhone extends Phone { constructor(brand,color,price,vase,small){ super(brand,color,price); this.vase = vase; this.small = small; } photo() { console.log("拍照"); } music() { console.log("音乐"); } static run() { console.log("程序开始启动"); } static end() { console.log("程序结束运行"); } } var a1 = new Phone("我的","你的",300); var a2 = new newPhone("12","23","34","我哦","掘金"); console.log(a1,'a1'); console.log(a2,'a2'); a2.call(); newPhone.run();