ES6的常用功能

2021-09-27 08:08:06 字數 1283 閱讀 9416

class函式

promise

let/const let定義可以被重新賦值,const定義的常量則不行

- 多行字串/模板變數 拼接更加簡單

var name = "zhangsan", age =20, html="";

html += ""

html += "+ name +

"html += "+ age +

"html += "

"const name = "zhangsan" , age = 20;

const html = `$

$ `;

解構賦值

var obj = 

var a = obj.a

var b = obj.b

var arr = ["***" , "yyy" , "zzz"]

var x = arr[0]

var z = arr[2]

const obj =

const = obj;

const arr = ["***" , "yyy" ,"zzz"]

const [x, y, z] = arr

塊級作用域

var obj = 

for(let item in obj)

console.log(item)

**函式預設引數**

function fn(a , b)

}function fn(a , b=0)

箭頭函式

var arr = [1, 2, 3];

arr.map(function(item))

const arr = [1, 2, 3];

arr.map(item => item+1)

arr.map((item , index) =>)

function fn()

var arr = [1,2,3]

arr.map(function(item))

}fn.call()

function fn()

var arr = [1,2,3]

arr.map(item =>

})}fn.call()

es6常用功能

前言 學習es6 的語法,記錄一些學習心得和總結 建構函式 在兩段 下分別列印下列 console.log typeof mathhandle function console.log mathhandle.prototype.constructor mathhandle true console....

es6常用功能

在es6之前,我們都是用var關鍵字宣告變數。無論宣告在何處,都會被視為宣告在函式的最頂部 不在函式內即在全域性作用域的最頂部 這就是函式變數提公升例如 function aa else 實際上是 function aa else 此處訪問 test 值為 undefined 而let和const都...

ES6之Class的常用功能解讀

class寫法更加清晰,可以將它看做語法糖。能夠讓物件原型的寫法更像 物件導向 的語法。let z parent newparent zhang console.log z parent zhangwen class之間可以通過extends關鍵字實現繼承疑問 子類如何覆蓋父類的值呢?繼承 時如何修...