Skip to content

Instantly share code, notes, and snippets.

@yesitskev
Created April 1, 2017 09:21
Show Gist options
  • Save yesitskev/3954f24430b8aeee50c98734cd94d728 to your computer and use it in GitHub Desktop.
Save yesitskev/3954f24430b8aeee50c98734cd94d728 to your computer and use it in GitHub Desktop.
Calling a function based off of a string value
var fn = self[("on_" + command)];
if (typeof fn === "function") {
fn(prefix, args);
} else {
console.log("No handler for: ", "on_internal_" + command);
}
@yesitskev
Copy link
Author

Just a brief example of calling a function based on string value and then invoking it. I used this in an IRC protocol parsing library which elevated a ton of if-else statements for server/client commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment