call 和 apply 有什么区别

apply

  • invoke the function with arguments as an array 数组做参数
theFunction.apply(valueForThis, arrayOfArgs)

call

  • requires the parameters be listed explicitly 直接值做参数
theFunction.call(valueForThis, arg1, arg2, ...)

A useful mnemonic is "A for array and C for comma"

What is the difference between call and apply?

results matching ""

    No results matching ""