Javascript call和apply的区别

Javascript call和apply的区别

  • 非严格模式:
    1. fn.call() // this ->window
    2. fn.call(null) // this ->window
    3. fn.call(undefined) // this ->window
  • 严格模式:
    1. fn.call() // this ->undefined
    2. fn.call(null) // this ->null
    3. fn.call(undefined) // this ->undefined
  • apply和call方法功能一样
  • 区别:
    1. call传参,一个个传
    2. apply,传参是数组

猜你喜欢

转载自blog.csdn.net/millions_02/article/details/80296678