PHP
比如你現在就可以這樣使用
$closure = function($param) { echo $param; };
//This one takes value of someVar and
//we later change the value of someVar outside it
// We assume that $somerVar is defined before this
$closure
比如在輸出HTML中閉包很有用
function item_list(array $items
//create the default formatter
if($formatter == null) {
$formatter = function($row) {
return
};
}
$html =
foreach($items as $item) {
$html
}
return $html;
}
From:http://tw.wingwit.com/Article/program/PHP/201311/21482.html