ES6 ES7 ES8語法總結

2022-04-12 07:02:31 字數 1690 閱讀 4624

es6

1. var let const

let,const具有塊級作用域,不具有變數提公升

const 用於不能被重新賦值的變數

2. 箭頭函式

我們經常要給**函式給乙個父級的this

常用辦法就是 var self = this 定義乙個變數接住他

使用 箭頭函式,this 將不會受到影響,可以直接用this呼叫父級的this

3. 字串

includes:

const string = 'food';

const substring = 'foo';

console.log(string.includes(substring));

返回的是布林值。

string.repeat(str,count)

如果 string.length < count 即插入str到count == string.length為止

4. 模板字串

const name = 'tiger';

const age = 13;

console.log(`my cat is named $ and is $ years old.`);

5.解構

結構陣列:

let [a, b, c, d] = [1, 2, 3, 4];

console.log(a);

console.log(b);

結構物件:

var luke = ;

var occupation = luke.occupation;

var father = luke.father;

let luke = ;

let = luke;

console.log(occupation);

console.log(father);

6.模組

暴露物件:

function sumthree(a, b, c) ;

引入:

import from 'math/addition';

7.引數

es6支援設定預設值:

function addtwonumbers(x=0, y=0) ;

object.entries(obj).foreach(([key, value]) =>`);

const data = response.data;

return data;

catch (error) {

console.log(error)

fetchdata(query).then(data => {

this.props.processfetcheddata(data)

es6 es7 es8學習筆記 教程

求冪運算子console.info 3 3 27async await 非同步 function dolater n,x n async function basicdemo basicdemo 也可以在async函式中返回乙個promise 然後就可以使用then了 函式宣告 async func...

es6 es7 es8 es9 es10各版本特性

let const 模板字串 箭頭函式 函式引數預設值 物件屬性簡寫 延展操作符 promise 類 class 模組化 import export array.prototype.includes 指數操作符 async await object.values object.entries pad...

ES6 ES7語法及原理實現

首先我們來看看小例子,這樣我們就知道差異了。let name zhangsan while true console.log name zhangsan 從上例子中,我們就已經發現了let的好處,let僅僅是作用於它所在的作用域當中,並不會影響到除作用域外的範圍。一般作用於值不變的變數,也稱之為常量...