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…


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail

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.


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail


Print Share Comment Cite Upload Translate
APA
Posts on LINQ to Fail | Sciencx (2022-12-01T21:24:57+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 2022-12-01T21:24:57+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 2022-12-01T21:24:57+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 2022-12-01T21:24:57+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: 2022-12-01T21:24:57+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/ | 2022-12-01T21:24:57+00:00
https://github.com/addpipe/simple-recorderjs-demo