假设我们有一个函数<img scr>
如下:
$card3
如果我想从$card1, $card2
调用if($card1=='0'){
$data = '
<html>
<head></head>
<body>
<img src = "https://www.stoningtonsoccerinternational.com/wp-content/uploads/2019/02/1_AC.png" height="5" width="5" >
</body>
</html>';
}else{
$data = '
<html>
<head></head>
<body>
<img src = "https://www.stoningtonsoccerinternational.com/wp-content/uploads/2019/02/red_back.png" height="5" width="5" >
</body>
</html>';
}
//card2 setting and fixing of front and back
if($card2=='0'){
$data = '
<html>
<head></head>
<body>
<img src = "https://www.stoningtonsoccerinternational.com/wp-content/uploads/2019/02/2_AD.png" height="5" width="5" >
</body>
</html>';
}else{
$data = '
<html>
<head></head>
<body>
<img src = "https://www.stoningtonsoccerinternational.com/wp-content/uploads/2019/02/red_back.png" height="5" width="5" >
</body>
</html>';
}
return $data;
}
,为什么我们必须将其作为回调传递?
foo
如果我们能做的就是:
function foo(){
alert("Hello, world!");
}
答案 0 :(得分:1)
因为我们可以将想要的任何函数传递给<input><button>Convert!</button>
,只要它与指定的函数签名匹配即可。用您的方式,在编写bar
时,我们必须提前知道foo
函数的名称。
之所以重要,是因为它减少了coupling。