Spivak: I use intellij and when I do auto format it removes that space anyway
Oshman: It always seems like a mistake when I see a space there though, no idea why
Stuchlik: Maybe because you’re used to intellij removing it
Defoor: Hey tcsc, would you by any chances have a decent reference/article or anything like that which explains and teaches how apply, call and bind work?
Heth: Apply and call are pretty simple though
Stuchlik: Techdeck: it’s got you! Maybe autocompletion will start recommending local restaurants next.
Tator: I’m sure there’s a plugin for that
Haener: The basic idea with apply is that you have an array of arguments
Hergert: And you want to call a function using those arguments.
Drish: Tcsc well, yeah, as concepts themselves are simple, but when it actual comes putting them in use things get confusing, at least for me :-/ but yeah, as a concept I do understand what they do
Ridner: In case anyone was wondering about my question, it’s called SVG stacking – reading about it now
Polito: RonRichie: what are you confused about then
Tosto: Aha, I just want to see cases when they are used and how so I can imagine the scenarios when they come to be useful :
Schoelman: Tcsc ahhh, one thing Im not sure though, they say this value is dependent upon as *who* is calling the function rather than *where* it’s been called, and that’s what apply and call solve?
Lillie: Var someNumbers = 1, 2, 7, 4, 2, 0, -7; Math.max.applynull, someNumbers
Martindale: Thats a pretty common use for apply
Bosson: Taking a function that takes a variable number of arguments and giving it an array
Ramotar: Does it iterate over every single item in array? like loops do?
Foxe: It can do it multiple at a time, potentially
Crapp: But, conceptually, yeah, it iterates over every item.
Rimer: For the this value, the first argument to call and apply both specify the this value.
Reeher: Normally it’s taken from what the function is called on.
Heitmuller: That makes sense, I just trying to get a feel of it, then why in this simple example it doesn’t work? should it print the values of this array? https://repl.it/BHJI
Ruffins: Again, the first argument is the this value.
Fitzgerrel: You could either change that to log out this inside that function, or call it as logger.applynull, arr
Finner: Both would be equivalent, however the first would be pretty wierd to see in reality.
Aken: Since having a free function that manipulates this is usually not super useful.
Nanez: Aha, I fixed it with setting this to null, but as I’ve previously experienced with this sample, it only prints the very first item in the array and stops? so thats why I was trying to figure out if it loops over all items, then isn’t it supposed to print all elements in the array?
Mincy: Math.max loops over the items in the array
Sarzynski: Your function would need to do that.
Schraeder: You’d loop over arguments
Troe: Ahh so looping system should be provided by my function, not by call and apply
Puckhaber: I had this perception as call and apply iterate over objects themselvesas like they loop themselves
Desmarias: No, they dont do the iteration
Vanlith: Oh that last one should say logger4. whatever
Gailun: Ahh, this is an awesome example: thanks a lot of this tcsc, let me dig into it and play around to get a feel, thanks for this
Robblee: How can I write this function without var use let or const instead. One way is to wrap calls in const object. Is there a more functional way of doing this?
Rupprecht: I don’t think FP has anything against declaring variables
Bjerk: Yeah But Is there way to avoid mutation and still achieve the same thing.