Last active
August 29, 2015 14:22
-
-
Save joelpalmer/40b5d35ad569b057a3fa to your computer and use it in GitHub Desktop.
Avoid eval if you have a name of an object's function in a string and use array syntax to call it
This file contains 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 funcName = "myfunc"; | |
var thingy = {age:27, | |
myfunc: function fun() { | |
console.log("It worked") | |
}}; | |
thingy[funcName](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment