What is the purpose of the open parenthesis on the callback?


#1

I have these two functions that work as expected:

//Fibonacci sequencer
const add_it = (number, previous, alist, nth, start) => {
    console.log(" *************  ")
    //console.log(alist)
    let next_number = previous + number;
    let next_start = start + 1
    if(next_start >= nth){
      console.log("-----------    final list  ------------")
      console.log(alist);
    }
    else {
      alist.push(next_number);
      console.log(alist);
      add_it(next_number, number, alist, nth, next_start);
    };
};
//////////////
//simple print the next number

const LineLog_count = ((c, max_num) => { //<-- the open parenthesis
    let x = c + 1
    console.log(x)
    if(max_num > x) {
      message = "repeating linelog :"
      console.log(message, x)
      LineLog_count(x, max_num) }
    else {
      let message = "done :::>>"
      console.log(message, x, max_num)
    }
});

My question is, What purpose does that open parenthesis have?


#2

That’s a self executing anonymous function. It is self invoking. You don’t need to give it a name and call it later.
But this is advanced stuff, why did you start with it? It’s a bit mind warping. Take it slow , gradually from the simple stuff to the more difficult.
Look at ex11 in LJSTHW, Zed talks about anonymous functions and gives an example of one in a callback. Have you seen that video? He explains exactly that, watching it now :wink: (minute 18:36 on)


#3

@nellietobey, @io_io I think this stuff is equivalent to a (anonymous) lambda function in Python.


#4

Yes, I thought about it too when I learned about lambda functions. They resemble very much.


#5

Oh man, I totally saw this and I think I used it but my brain is drawing a blank. Did you see it up somewhere and they didn’t explain it?


#6

I was trying to make callbacks, see how they work, and I’m pretty sure I had the idea all wrong. You explain it in the video, I just didn’t pay enough attention the first time around.

°<