简体   繁体   中英

how to pass the functions with args in an inline function in JS?

function emotions(myString, myFunc) {
    console.log("I am " + myString + ", " + myFunc(2));
}

// your code goes here
// call the emotions function here and pass in an
 var laugh = function(max){
    var str ="";
    for(var i=0; i<max ;i++){
        str += "ha";
    }
    return str+"!";
};

// inline function expression
emotions("happy", laugh(2));

can anyone revert me , where I made a mistake? Thanks to all in advance

The emotions function accepts 2 arguments- 1. myString - which is a string 2. myFunc - which is a function

The laugh function returns a string. laugh(2) => haha!

Hence, you should just pass laugh as a parameter to emotions as follows emotions("happy", laugh)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM