search

Home  >  Q&A  >  body text

Question about anonymous functions

var a=function(x){return x*x;} What does a mean that can be put into other functions to operate? Is it called or imported? Can you give an example?

MrSwanMrSwan2440 days ago1684

reply all(1)I'll reply

  • 灭绝师太

    灭绝师太2018-04-20 13:05:34

    In the video: var a=function (x){return x*x;}//Assign the function as a value to the variable a

    Call the method such as:

    var pf=function ( x){return x*x;}//Find the square

    var lf=function(x){return x*x*x;}//Find the cube

    // Call the function to get the corresponding result

    function doFunc(func,value){

    return func(value);

    }

    console.log(doFunc( pf,10));

    console.log(doFunc(lf,10));


    reply
    5
  • Cancelreply