If you use a function as an argument for a function as shown in Position(Math.random()); below,
Is it called a high-order function to distinguish a function of an argument from a general function?
let Position=(mathRandom)=>{
targetItem.style.top=(mathRandom*100) + '%';
};
let setClickItem1 = setInterval() = > {
Position (Math.random());
}, speed);
Also, it's complicated with the callback function, but is the function that is passed to the function called the callback function, not the function used in the argument?
The difference is subtle.
A higher-order function is a function that can be given or returned as an argument.
In other words, it is a function that can handle functions.
This is not a function of the argument (which may also be a higher-order function).
The callback function is called that for the purpose of the function passed.
For example,
Suppose you request data from a server and draw it on the screen with the data you received.
data=loaddata();
draw(data);
In this way,
You have to wait for loaddata()
to finish.
So,
loaddata(draw);
Pass the function as shown in
Have loaddata
itself run draw(data);
at the end of the load.
I mean, give me your phone number and call me when you're done with your work, and then I'll do my job.
That's how it feels.
This is probably what they call a callback.
Another example is
Functions add
and
to add two arguments.
The function sub
that subtracts two arguments is
Yes,
calc
calculates by applying two arguments and passed functions is
calc(x,y,add);
when invoked as follows:
calc
does a call like add(x,y)
, but
In such cases, add
is not called a callback function (I think).
Therefore, it is called that way depending on the purpose of the function you pass.
© 2024 OneMinuteCode. All rights reserved.