JavaScript call and apply

A colleague recently came across this line in our codebase that I wrote:
binding.vehicle.involvements.push.apply(binding.vehicle.involvements, vehicle.involvements); What the overall result of the code is isn’t particularly important, the part th…

A colleague recently came across this line in our codebase that I wrote:
binding.vehicle.involvements.push.apply(binding.vehicle.involvements, vehicle.involvements); What the overall result of the code is isn’t particularly important, the part that tripped them up (and made them think I’m on drugs I’m not actually on) was this:
binding.vehicle.involvements.push.apply(binding.vehicle.involvements, vehicle.involvements); Now the involvements property is an array in both scenarios which exposes a push method, the confusion was around what the apply method does and why I was even using it.


Print Share Comment Cite Upload Translate
APA
Posts on LINQ to Fail | Sciencx (2024-03-29T02:26:05+00:00) » JavaScript call and apply. Retrieved from https://www.scien.cx/2013/07/04/javascript-call-and-apply/.
MLA
" » JavaScript call and apply." Posts on LINQ to Fail | Sciencx - Thursday July 4, 2013, https://www.scien.cx/2013/07/04/javascript-call-and-apply/
HARVARD
Posts on LINQ to Fail | Sciencx Thursday July 4, 2013 » JavaScript call and apply., viewed 2024-03-29T02:26:05+00:00,<https://www.scien.cx/2013/07/04/javascript-call-and-apply/>
VANCOUVER
Posts on LINQ to Fail | Sciencx - » JavaScript call and apply. [Internet]. [Accessed 2024-03-29T02:26:05+00:00]. Available from: https://www.scien.cx/2013/07/04/javascript-call-and-apply/
CHICAGO
" » JavaScript call and apply." Posts on LINQ to Fail | Sciencx - Accessed 2024-03-29T02:26:05+00:00. https://www.scien.cx/2013/07/04/javascript-call-and-apply/
IEEE
" » JavaScript call and apply." Posts on LINQ to Fail | Sciencx [Online]. Available: https://www.scien.cx/2013/07/04/javascript-call-and-apply/. [Accessed: 2024-03-29T02:26:05+00:00]
rf:citation
» JavaScript call and apply | Posts on LINQ to Fail | Sciencx | https://www.scien.cx/2013/07/04/javascript-call-and-apply/ | 2024-03-29T02:26:05+00:00
https://github.com/addpipe/simple-recorderjs-demo