函数当作参数传递

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<script type='text/javascript'>
    function callSomeFunction(someFunction, someArgument) {
        return someFunction(someArgument);
    }
    
    function add10(num) {
        return num + 10;
    }
    
    var result = callSomeFunction(add10, 10);
    console.log(result);
    
    function getGreeting(name) {
        return 'Hello ' + name;
    }
    
    var result2 = callSomeFunction(getGreeting, 'Nicholas');
    console.log(result2);
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/mtima/p/2990952.html