javascript エラー「TypeError: |this| is not a function inside Function.prototype.bind」の解決方法
- 作成日 2022.07.07
- javascript
- javascript
![javascript エラー「TypeError: |this| is not a function inside Function.prototype.bind」の解決方法](https://mebee.info/wp-content/uploads/2022/02/javascript-1-890x500.png)
javascriptで、エラー「TypeError: |this| is not a function inside Function.prototype.bind」が発生した場合の原因と解決方法を記述してます。
環境
- OS macOS Big Sur
- ブラウザ safari 15.0
エラー内容
以下のコードを実行した際に発生。
const obj = {
fn:function (){ console.log(this);}
}
const arr = [0, 1]
console.log(
arr.forEach(obj.fn.bind)
)
エラーメッセージ
TypeError: |this| is not a function inside Function.prototype.bind
画像
![](https://mebee.info/wp-content/uploads/2022/02/image-356.png)
原因
関数の括弧がないため
解決方法
括弧を使う
const obj = {
fn:function (){ console.log(this);}
}
const arr = [0, 1]
console.log(
arr.forEach(obj.fn.bind())
)
実行結果
![](https://mebee.info/wp-content/uploads/2022/02/image-357.png)
-
前の記事
ubuntu22.04 kotlinをインストールする 2022.07.07
-
次の記事
MySQL コマンドを途中でキャンセルする 2022.07.07
コメントを書く