this...的指向

139 阅读1分钟

很多时候都会被 this 到底指向的谁很迷糊 ,列举 了一下 函数调用时 this 指向谁

1. fn() this => window

2. obj.fn() this => obj

3. fn.call(xxx) this => xxx

4. fn.apply(xxx) this => xxx

5. fn.bind(xxx) this => xxx

6. new Fn() this => 指向的是新的对象