作者gpmm (银色)
看板PHP
标题Re: [请益] callback与匿名函式
时间Sun Sep 22 17:19:39 2013
※ 引述《edash (团长)》之铭言:
: 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是否完全贴切?)的限制。
these functions tend to be localized and temporary
这句应该只是单纯说这种函式倾向於局部性 / 暂时性会使用到的。
To reflect the transient nature of the callback, create and use …
应对着这种暂时性的需求,你可以采用匿名函式来处理(也就是所谓的 closure)。
: 最後一句「To reflect...anonymous function」,我推测应该是因为前面提到函式有
: 「localized and temporary」的特性,才提到匿名函式可以因应callback的特性。
: 反覆思考後,还是想不太出来「transient nature」是什麽意思,transient在字典里是
: 「短暂的; 一时的; 瞬间的」等意思,感觉都搭不太起来。希望有板友能解惑
: 关於个人解读的部分,如有错误,也请板友多多指教。谢谢
--
嗯,其实我也通篇翻错?(惊
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.34.144.68
1F:推 edash:谢谢回应,我再多想想。 09/23 15:33