thisを関数に渡したい
状況
jsでthisを関数の引数として渡したい。
しかしそのまま引数の名前をthis
とするとエラーになる。予約語だから引数の名前にはできないのだ。
かわりに_this
とすればよい。
コード
$('input[type="text"]').on('click', '#mandatory', function() { do_something(this); } function do_something(_this) { // なんかの処理 }
jsでthisを関数の引数として渡したい。
しかしそのまま引数の名前をthis
とするとエラーになる。予約語だから引数の名前にはできないのだ。
かわりに_this
とすればよい。
$('input[type="text"]').on('click', '#mandatory', function() { do_something(this); } function do_something(_this) { // なんかの処理 }