Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention of callback in node.js

Is there a naming convention for the name of the callback function you pass to async methods in node.js? I've seen a number of different names used and I generally pick a name that makes sense in the given context.

Has a convention emerged?

like image 504
Sam Shiles Avatar asked Jan 04 '14 21:01

Sam Shiles


1 Answers

I think there are no general naming convention. I use a normal speaking name in camelCase. My co-worker prefers the Callback postfix like handleUserListCallback. My other co-worker prefers the Handler postfix and another prefers the __ (double underscore) prefix (yes he was a python believer).

For naming the variable: Name it clearly.

function fetch(parameter, callback) {}
function worker(parameter, done) {}
function job(parameter, finish) {}

Try to use an understandable naming. One that you can understand and other who tries to read or improve your code and be consequent.

like image 120
yitsushi Avatar answered Oct 07 '22 04:10

yitsushi