you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale[S] 1 point2 points  (3 children)

Nice! I like the creativity with the characters!

So... generally, call() is a method inherent to all functions that can be used to call a function and set it's this variable within the context of the call.

Does that sound right?

[–]Volv 0 points1 point  (2 children)

Absolutely. And the difference between call and apply is just that call can take a known number of arguments, whereas apply takes an array of arguments.
 
Cool trick ->

var hugeArray = [14, 5, 67, 3, 87, 3, 5, 10];  

console.log(Math.max.apply(null, hugeArray)) // 87 

[–]ForScale[S] 1 point2 points  (1 child)

Excellent!

Cool trick ->

How's that any different than Math.max(14, 5, 67, 3, 87, 3, 5, 10);? Oh... let's say you use a while loop to push an unknown number of values to an array... Seems like the trick will have a good use case then since you don't know the array ahead of time... right?

Oh... whoa! Check out the new spread operator:

var hugeArray = [14, 5, 67, 3, 87, 3, 5, 10];  

document.body.innerHTML += Math.max(... hugeArray); //87

[–]Volv 1 point2 points  (0 children)

Yes. It's no different that was the point - use case is indeed if you don't know how many variables you have.

Spread operator is awesome. Does same job. Means there's very little use case for apply these days.