每个函数都有,除了箭头函数

如何传 arguments

调用 fn 即可传 arguments
fn (1,2,3) 那么 arguments 就是[1,2,3] 伪数组
image.png

如何传 this

如果不给任何参数,this默认指向window
image.png

用 call 传 this

image.png
如果call传的不是对象,JS会帮你自动封装成对象

如何禁用这个特性
image.png
一般不使用

fn.call(xxx, 1, 2, 3) 传 this 和 arguments

image.png
**

call

需要手动把person 传到函数里,作为this
image.png

不用this时,需要找个东西占位,可以是undefined,null等等
image.png

this 的两种使用方法

隐式传递

image.png

显示传递

image.png

使用 bind 绑定this

使用.bind 可以让 this 不被改变

image.png

.bind 还可以绑定其他参数

image.png

箭头函数

里面的 this 就是外面的 this
image.png
就算加call也没用
image.png

立即执行函数(用的少)

在匿名函数前面加个运算符即可
!、() 、~、+、- 都可以
推荐使用 !

JS中唯一用到分号的地方
image.png