以下のようにES6のclass構文で継承元のメソッドを呼び出すとき無名関内からsuperを使った時エラーとなっていしまい呼び出せないのですが、何か良い方法はあるでしょうか。
継承しているのだからthisを使えば良いのですが、なぜsuperで呼べないのか、どうすれば呼べるのか、this, super以外に方法があるのかを知りたいと思っています。
よろしくお願い致します。
JavaScript
1 class A{ 2 constructor(){ 3 this.aaa = "a"; 4 } 5 6 getA(){ 7 return this.aaa; 8 } 9 } 10 11 class B extends A{ 12 constructor(){ 13 super(); 14 this.bbb = "b"; 15 console.log(super.getA()); //a 16 (function(){ 17 console.log(super.getA()); //出力されないどころかスクリプトが走らない 18 })(); 19 20 } 21 } 22 23 (function(){ 24 new B(); 25 })(); 26
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/25 09:19