【笔记】改变this的指向

前言

改变Javascript中this的指向

方法1

  • 保存this为变量that_this

方法2

  • 使用call()函数,将需要改变this指向的函数调用call()函数,将改变后想要指向的函数作为参数传递给call()函数

方法3

  • 使用apply()函数,将需要改变this指向的函数调用apply()函数,将改变后想要指向的函数作为参数传递给apply()函数

方法4

  • 使用bind()函数,将需要改变this指向的函数调用bind()函数,将改变后想要指向的函数作为参数传递给bind()函数

完成

参考文献

哔哩哔哩——Python小清风