Skip to content

Instantly share code, notes, and snippets.

@joshtwist
Last active December 11, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshtwist/4639860 to your computer and use it in GitHub Desktop.
Save joshtwist/4639860 to your computer and use it in GitHub Desktop.
Dispatching to different functions inside a script based on the parameter
function read(query, user, request) {
var dispatch = {
op1 : operation1,
op2 : operation2,
}
if (request.parameters.operation && dispatch.hasOwnProperty(request.parameters.operation)) {
dispatch[request.parameters.operation](query, user, request);
return;
}
else
{
// default path for execution
request.execute();
}
}
function operation1(query, user, request) {
request.respond(200, "this result is from operation1");
}
function operation2(query, user, request) {
request.respond(200, "this result is from operation2");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment