下記のコードですが、クラスの中の関数にfunctionをつけると動きません。何故でしょう。そういう。また、下記の実行結果がTestB -> TestAのようにTestBからでる理由は何故なのでしょうか。また、なぜ、クラス内の関数を呼ぶときは()
を付けなきゃいけないのに、getを呼ぶときは()
省いても大丈夫なのでしょうか。
js
1class TestA { 2 3 get test_area() 4 { 5 return this.test_calcArea(); 6 } 7 8 test_calcArea() 9 { 10 $('body').after(`<p>TestA</p>`); 11 } 12} 13 14const test = new TestA(); 15test.test_area; 16//TestA 17 18 19function TestB(){ 20 $('body').after(`<p>TestB</p>`); 21} 22TestB(); 23//TestB
回答4件
あなたの回答
tips
プレビュー