原型对象的意义函数
classthis
实例属性,写入在constructor中spa
静态属性与方法,写在constructor外,用static修饰code
原型对象,写在constructor外对象
<script> class Person { constructor(name, age) { this.name = name; this.age = age } // 挂载到原型对象上 Say() { console.log('I am human') } } console.log(new Person('ss', 14)) </script>
继承,子类继承使用extends关键字,当子类须要写入私有的属性,必须添加constructor以及super(),super() 至关于父类构造器的引用,this关键字必须在super以后blog
<script> class Person { constructor(name, age) { this.name = name; this.age = age } // 挂在到原型对象上 Say() { console.log('I am human') } } class Student extends Person { constructor(name, age, id) { super(name, age) this.id = id } } console.log(new Student('ww', 14, 14)) </script>