Javascriptでclassを作成しています.
Javascript
1class ChartResize{ 2 constructor(w){ 3 this.myWindow = w; 4 5 this.setEvent(); 6 } 7 8 setEvent(){ 9 this.myWindow.addEventListener('beforeunload', function(e) { 10 this.clearWindowName(); 11 e.returnValue = 'unload'; 12 }, false); 13 } 14 15 clearWindowName(){ 16 this.myWindow.name = ""; 17 } 18 19} 20
constructorでwindowを渡し,eventListenerにbeforeunloadを設定しています.
上記処理を実行後,ブラウザでF5をクリックすると,beforeunloadイベントは発生しますが,
this.clearWindowName()がundefinedになってしまいます.
どのようにすればクラス内のeventLister内で関数を実行できますでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/23 04:37