ES6 里面的 class
生活随笔
收集整理的這篇文章主要介紹了
ES6 里面的 class
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ES5 對象的寫法
let x = 10,y = 20;const obj = {x: x,y: y,sum: function () {return this.x + this.y;} };ES6 對象的寫法
const obj = {x,y,sum() {return this.x + this.y;} };class 有點類似 java 的 class
class Person { // 類名大寫// 私有屬性和方法 寫在 construtor 里面constructor(name, age) {this.name = name;this.age = age;this.showName = function () {console.log(this.age);}}// class 內部的原型里面只允許寫方法sayName() {console.log('I am ' + this.name);} }const person = Person('mary', 19)constructor 里面是對象的私有屬性和私有方法 類里面是原型上的方法
總結
以上是生活随笔為你收集整理的ES6 里面的 class的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android x86_64 服务器运行
- 下一篇: 窗口刷新 Invalidate Upda