es6中class類繼承的super我可以理解為是父類的例項麼

時間 2021-06-08 14:01:20

1樓:Tianfan

執行過程,

是把 this 這個物件,放進 super 進行包裝後返回到 this 上。

其實 this 也是函式的引數,你就能理解了。

2樓:謝然

super不是父類的例項,只是乙個為了你方便訪問到父類函式(包括建構函式)的關鍵字

而且即使發生了繼承,也只有乙個物件例項被建立可以看一下我這邊專欄文章,有點長,但應該能解你的惑https://

zhuanlan /p/354146530

3樓:navegador

摳字面的話我認為不能, 一次new 例項只會產生1個

實驗1:

var container快取

class Parent , Child {} ]

> container[0] === container[1一次new 例項只有乙個

true

>實驗2

var po =

}class C extends P {

constructorlet maybep = superconsole.log(super.constructorconsole.

log("--->",maybep!==this,maybep===thisconsole.log("in c:

",new.targetvar c = new C()

/*in p: [class C extends P]

[class P]

---> false true

in c: [class C extends P]

*/ECMA:

SuperCall : super Arguments

1. Let newTarget be GetNewTargetgt;

2. Assert: Type(newTarget) is Object.

3. Let func be ! GetSuperConstructorgt;

4. Let argList be ? ArgumentListEvaluation of Arguments.

5. If IsConstructor(func) is false, throw a TypeError exception.

6. Let result be ? Construct(func, argList, newTargetgt;

7. Let thisER be GetThisEnvironment1. Let env be the running execution context's LexicalEnvironment.

2. Repeata. Let exists be env.

HasThisBindingb. If exists is true, return envc. Let outer be env.

[[OuterEnvd. Assert: outer is not nulle.

Set env to outer.

8. Return ? thisER.BindThisValue(resultgt;繫結this child 接手

ES6 中的Generator 函式有何特別之處?

個人是這麼理解和記憶的。迭代器 Iterator 的出現,是為了便於遍歷新出現的資料結構,如Map Weakmap Set相較於之前的Object Array,及自定義的資料結構 function makeIterator array 並且,乙個資料的結構體如果是可迭代的 Iterable 比如自帶...

如何理解ES6的yield ?

roscoe 我怎麼覺得Generator函式改為叫Ratchet函式會更形象些yield就是棘輪的停止,next 的執行就是棘輪的下一次的執行,狀態往復直至done的狀態為true而止。 已重置 當我們寫乙個函式在function後面或者函式名字前面加上乙個 呼叫這個函式返回的就是Generato...

es6的forEach如何跳出迴圈?

刃舞 嚴格來說 Array.forEach 是迭代方法不是流程控制語句,所以不需要提供類似 continue break 的操作 如果你需要跳出迴圈,應該用流程控制語句 for 寫迴圈 威老 Valor throw?try catch?看得我心臟病都要犯了。some 不香嗎?判斷是否存在至少乙個符合...