前提・実現したいこと
javascriptでクリックイベント時に値の変更を行いたい。
clickしたら、this.isplaying = trueとなるようにしたいです。
発生している問題・エラーメッセージ
main.js:20 Uncaught ReferenceError: Invalid left-hand side in assignment at HTMLDivElement.<anonymous> (main.js:20)
該当のソースコード
javascript
1{ 2 class A { 3 constructor(){ 4 this.sth1 = document.getElementById('sth1'); 5 this.isplaying = false; 6 } 7 getIsplaying(){ 8 return this.isplaying; 9 } 10 getSth(){ 11 return this.sth1; 12 } 13} 14const a = new A(); 15 16 class B { 17 constructor(){ 18 a.getSth().addEventListener('click' , ()=>{ 19 a.getIsplaying() = true; 20 console.log(a.getIsplaying()); 21 }); 22 } 23 } 24 new B(); 25}
html
1<!DOCTYPE html> 2 <html lang="ja"> 3 <head> 4 <meta charset="utf-8"> 5 <link rel="stylesheet" href="css/styles.css"> 6 </head> 7 <body> 8 <div id="sth1"></div> 9 <script src="javascript/main.js"></script> 10 </body> 11 </html>
回答2件
あなたの回答
tips
プレビュー