這是在看阮一峰老師的es6中關(guān)于類遇到的問題。代碼如下,雖然答大體意思我知道,不過不是太能理解super.x輸出為undefined。classA{constructor(){this.x=1;}}classBextendsA{constructor(){super();this.x=2;super.x=3;//super.x.call(this),即為this.x。但屬性沒有call方法//super.x即為A.prototype.x,A中的x為實(shí)例的屬性,而實(shí)例的屬性和方法都無法在原型上訪問到(能懂)console.log(super.x);//undefined為什么這里讀到的一定是A.prototype.x,而不會是this.x???console.log(this.x);//3}}letb=newB();
感覺class的super用作對象還是有點(diǎn)繞,請教大佬給一個透徹的解釋
肥皂起泡泡
2019-10-08 10:45:40