JS 上 call, aplly, bind 差異


Posted by YongChenSu on 2020-12-08

三者差異

  • call、apply皆是回傳 function 執行結果
  • bind方法回傳的是綁定 this 後的原函數

call 以及 aplly 的差異

call 接受一連串的參數,而 apply 接受一組陣列形式的參數。

效能上 call 優於 apply

在不确定参数的情况下,如果不考虑性能,代码层面用apply来写会简洁很多。不过你能确认参数长度的时候,最好都用call方法而不用apply。

參考資源


#程式導師實驗計畫第四期 #前端







Related Posts

自動化測試 x Puppeteer - 玩偶QA參一咖 Day01

自動化測試 x Puppeteer - 玩偶QA參一咖 Day01

Synthetic Control Unleashed: Crafting a Data Twin to Understand Interventions

Synthetic Control Unleashed: Crafting a Data Twin to Understand Interventions

Leetcode 刷題 pattern - Fast & Slow Pointer

Leetcode 刷題 pattern - Fast & Slow Pointer


Comments