this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象
example:
function Eat(apple){ this.apple=apple//谁用new去实例化this就指代谁}var lilei=new Eat(apple);//this指代lileivar hanmeimei=new Eat(apple);//this指代hanmeimei 当this指代的内容不是自己想要的时候,可以用bind进行绑定 example: 没有用bind绑定时 使用bind绑定
时间: 2024-08-06 11:55:11