1、面向对象
创建类:
<script>/* class */function Person(name,age){this.name = name;this.age = age;}var cheng = new Person("lisi",19);console.log(cheng)</script>
2、ES6中构造函数
构造函数就是构造一个对象的函数
constructor(){
}
<script>/* 构造函数就是构造一个对象的函数 */class Person{constructor(name,age){console.log("hello world")this.name = name;this.age = age;}}var li = new Person("lisi",18)</script>
3、extend继承
在继承的构造函数中super必须放在第一行
class Apple extends Computer{
constructor(name,price,skill){
super(name,price);
this.skill = skill;
}
}
子类会自动继承父类的方法
<script>class Computer{constructor(name,price){this.name = name;this.price = price;}sayName(){console.log(this.name)}sayPrice(){console.log(this.price)}}class Apple extends Computer{constructor(name,price,skill){/* 在继承的构造函数中super必须放在第一行 */super(name,price);this.skill = skill;}}/* 子类会自动继承父类的方法 */var a = new Apple("苹果电脑",8888,"设计牛逼")console.log(a);a.sayName();a.sayPrice();</script>

1、class可以定义一个类
2、constructor 构造函数,new关键字实例化一个对象的时候调用
3、super指父类
<script>/*1、class可以定义一个类2、constructor 构造函数,new关键字实例化一个对象的时候调用3、super指父类*/class Person{constructor(name,age){console.log("p")this.name = name;this.age = age;}sayName(){console.log(this.name);}}class Student extends Person{constructor(name,age,skill){console.log("s")super(name,age);this.skill = skill;}}var s = new Student("lisi",19,"wechat")s.sayName();</script>

