function getPerformActionFunction(someParameter) {
return function() {
performAction(someParameter);
}
}
你会怎样称呼
getPerformActionFunction
以表明它并不执行操作,而是返回执行操作的函数?这是一个JavaScript的示例,如果有JavaScript的惯例更好,但也对其他语言感兴趣,如果答案不同的话。function getPerformActionFunction(someParameter) {
return function() {
performAction(someParameter);
}
}
getPerformActionFunction
以表明它并不执行操作,而是返回执行操作的函数?这是一个JavaScript的示例,如果有JavaScript的惯例更好,但也对其他语言感兴趣,如果答案不同的话。不确定是否在任何风格指南中,但我相当喜欢使用-er
后缀来表示能够执行某个操作的东西。
例如:getActionPerformer
、fooHandler
或XMLTransformer
我已经在C#、Java和Clojure中使用了这种风格,看起来效果还不错。