原型對象的意義函數
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>