作者edash (团长)
看板PHP
标题[请益] callback与匿名函式
时间Sun Sep 22 15:14:48 2013
Some PHP functions use a function you provide them with to do part of their
work. For example, the usort() function uses a function you create and pass to it
as a parameter to determine the sort order of the items in an array.
Although you can define a function for such purposes, as shown previously,
these functions tend to be localized and temporary. To reflect the transient
nature of the callback, create and use an anonymous function (also known as a
closure).
节录书上两段对匿名函式(anonymous function)的介绍,第一段提及某些函式可能会利
用其他函式完成运作,并举usort()为例子。
第二段则是说明前一段的情境其实也可以自行定义函式解决,只是函式却有可见范围与内
部变数生命周期(不太确定自己解读localized and temporary是否完全贴切?)的限制。
最後一句「To reflect...anonymous function」,我推测应该是因为前面提到函式有
「localized and temporary」的特性,才提到匿名函式可以因应callback的特性。
反覆思考後,还是想不太出来「transient nature」是什麽意思,transient在字典里是
「短暂的; 一时的; 瞬间的」等意思,感觉都搭不太起来。希望有板友能解惑
关於个人解读的部分,如有错误,也请板友多多指教。谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.248.90.167
※ 编辑: edash 来自: 111.248.90.167 (09/22 15:15)