call方法的作用是调用函数,并且改变函数的this指向,this指向为call方法的第一项,其余后面的都是参数。
apply() 与call()非常相似,不同之处在于提供参数的方式,apply()使用参数数组,而不是参数列表。
改变定时器中的this指向,我们有个更好的方法:bind
bind()创建的是一个新的函数(称为绑定函数),与被调用函数有相同的函数体,当目标函数被调用时this的值绑定到 bind()的第一个参数上
call方法的作用是调用函数,并且改变函数的this指向,this指向为call方法的第一项,其余后面的都是参数。
apply() 与call()非常相似,不同之处在于提供参数的方式,apply()使用参数数组,而不是参数列表。
改变定时器中的this指向,我们有个更好的方法:bind
bind()创建的是一个新的函数(称为绑定函数),与被调用函数有相同的函数体,当目标函数被调用时this的值绑定到 bind()的第一个参数上
1、对象中的thisvar name = 'Tom';let obj = { name: this.name,};console.log(obj);
改变this指向的三个方法
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M