← 返回完整题库
JavaScript简单

改变this指向的方法有哪些?

参考答案

  1. call(thisArg, a, b):立即调用,参数逐个传
  2. apply(thisArg, [a, b]):立即调用,参数用数组
  3. bind(thisArg, ...args):返回新函数,永久绑定,可预设参数
  4. 箭头函数:词法绑定,取定义处外层 this
  5. 调用方式:obj.fn() 隐式绑定;new Fn() 绑定到新实例
  6. 事件监听:addEventListener 中 this 为绑定元素
  7. 某些 API 支持 thisArg 参数(forEach/map 的第二个参数)

本题来自 计算机知识面试题库,共 921 道题。