cachaito
10/26/2015 - 9:27 AM

Use of .apply()

Sidenote after: https://www.reddit.com/r/javascript/comments/3q20uu/function_invocationwhy_use_call_and_apply/ - passing arguments to apply is actually unfortunately slow. It's much faster to (if you know the number of arguments) pass each explicitly to call. Handy article: http://alexperry.io/personal/2016/04/03/How-to-use-apply-bind-and-call.html

var tab = [2,3,4,6,1];  
Math.max(tab); //NaN
Math.max.apply(null, tab); //6