錯誤之處,歡迎指正荔茬,持續(xù)更新中废膘。
1. 基礎(chǔ)
1. 列舉幾個ES6
新增的數(shù)組方法。
includes
慕蔚、fill
丐黄、find
2. 簡單說明ES6
箭頭函數(shù)this
的指向。
箭頭函數(shù)內(nèi)的this
指向定義該函數(shù)時所在的作用域的this
指向孔飒,而不是使用時所在的作用域的this
指向灌闺。
3. 執(zhí)行下列代碼控制臺的輸出結(jié)果是什么?
class Example {
constructor(name){
this.name = name;
this.fn = function () {
console.log(this.name);
}
}
static fn() {
console.log(this.name + '@example.com');
}
}
const test = new Example('chris');
test.fn();
Example.fn();
控制臺輸出結(jié)果為:
chris
Example@example.com
坏瞄。
4. 簡單介紹迭代器桂对。
迭代強(qiáng)調(diào)的是依次取數(shù)據(jù),并不保證取多少個數(shù)據(jù)鸠匀,也不保證把所有數(shù)據(jù)取完蕉斜,遍歷強(qiáng)調(diào)的是要依次把所有數(shù)據(jù)都取完,需要知道集合的長度。
JavaScript
規(guī)定宅此,如果一個對象obj
具有next
方法机错,并且next
方法返回一個對象,該對象格式為如下所示父腕,那么稱這個對象obj
為迭代器弱匪。
const obj = {
next() {
return {
value: null,
done: null
}
}
}
-
next
方法:用于得到下一個數(shù)據(jù)。 -
value
屬性:下一個數(shù)據(jù)的值侣诵。 -
done
屬性:Boolean
痢法,是否迭代完成。