Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the naming convention for a function that returns a function?

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.

like image 558
Davy8 Avatar asked Dec 22 '11 16:12

Davy8


People also ask

How do you call a function that returns a function?

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.

How should functions be named?

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.

Can you return a function?

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.


1 Answers

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.

like image 175
mikera Avatar answered Sep 27 '22 18:09

mikera