function getPerformActionFunction(someParameter) {
return function() {
performAction(someParameter);
}
}
What would you call getPerformActionFunction
to indicate that it doesn't perform the action, but rather returns a function which performs the action?
Example is Javascript, and if there's a Javascript convention that's preferred, but also interested in other languages if the answer differs.
Approach: First call the first function-1. Define a function-2 inside the function-1. Return the call to the function-2 from the function-1.
Naming Convention for Functions So, similar to variables, the camel case approach is the recommended way to declare function names. In addition to that, you should use descriptive nouns and verbs as prefixes. For example, if we declare a function to retrieve a name, the function name should be getName.
A function is an instance of the Object type. You can store the function in a variable. You can pass the function as a parameter to another function. You can return the function from a function.
Not sure if it's in any style guides, but I quite like the -er
suffix to suggest something that is able to do an action.
e.g. getActionPerformer
or fooHandler
or XMLTransformer
I've used this sort of style in C#, Java and Clojure an it seems to work OK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With