consoelエラーが発生し続ける:予期しないトークンthisどうすればいいですか?
この機能を動作させるにはどうすればよいですか? 、あなたはnew
キーワードを使用する場合
var _this = this;
this.Map = new Button({
text: "Map",
press: function(event){
pop.open(_this._Map);
}
});
consoelエラーが発生し続ける:予期しないトークンthisどうすればいいですか?
この機能を動作させるにはどうすればよいですか? 、あなたはnew
キーワードを使用する場合
var _this = this;
this.Map = new Button({
text: "Map",
press: function(event){
pop.open(_this._Map);
}
});
あなたはこのように、あなたのプレス機能にこれをバインドする必要がありインタプリタは新しい空オブジェクトを作成し、コンストラクタ内の "this
"というキーワードをバインドしたコンストラクタ(ここではButton)を にバインドして呼び出しますこれと同じではありませんthis.map
あなたは明示的にButton()
を呼び出していないので、これをバインドすることはできません。あなたは次のように行うことができます :
var self = this;
this.Map = new Button({
text: "Map",
press: function(event){
pop.open(self._Map);
}
})
:
function onPress(event){
pop.open(this._Map);
}
this.Map = new Button({
text: "Map",
press: onPress.bind(this)
})
またはあなたはまた、このアプローチを使用することができます。
this.Map = new Button({ //button is a control so dont worry if it doesn't make sense
text: "Map",
press: function(event){
pop.open(this._Map);
}
})