Created
April 1, 2017 09:21
-
-
Save yesitskev/3954f24430b8aeee50c98734cd94d728 to your computer and use it in GitHub Desktop.
Calling a function based off of a string value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fn = self[("on_" + command)]; | |
if (typeof fn === "function") { | |
fn(prefix, args); | |
} else { | |
console.log("No handler for: ", "on_internal_" + command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.