- 683 名前:デフォルトの名無しさん mailto:sage [2022/04/24(日) 07:36:29.99 ID:zeaUlF5d0.net]
- >>664
よくあるのは、無名のcallback 関数のthis が、window を指してしまうのを避けるために、bind する。 setTimeout( function( ) { this.count++ }.bind( this ), 100 ) この場合、thisをthatに代入して使うのも簡単。 const that = this setTimeout( function( ) { that.count++ }, 100 ) ES2015では、アロー関数も使える。 setTimeout( ( ) => { this.count++ }, 100 ) だから最近は、bind する事も減った JavaScript は、thisの変動が非常に難しい。 thisが何を指しているのか分からない それで、jQuery の$( this ) がよく使われる
|

|