舉個例子:
local?m?=?{}?local?list?=?{name="hello",age=12}?
m.call_back_fun_print?=?function(printID)?
print(printID?..?"-->"?..?list[printID])?
end?
m.add_list?=?function(key,value,call_back_fun)?
key?=?tostring(key)?
list[key]?=?value?
call_back_fun(key)?
end?
m.add_list("address","beijing",m.call_back_fun_print)?--address-->beijing?
return?m
註:C、C++和Pascal允許將函數指針作為參數傳遞給其它函數。其它語言,例如JavaScript,Python,Lua,Perl和PHP,允許簡單的將函數名作為參數傳遞。
詳情可參考這篇博客:/shimazhuge/article/details/41680909?utm_source=tuicool&utm_medium=referral
望對妳有所幫助!