Created
April 26, 2013 16:49
-
-
Save dustintheweb/5468690 to your computer and use it in GitHub Desktop.
Pass a string into a function and concatenate it into a parseable var
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
// >> pass a string to the middle of a declared var >>>>>>>>>>>>>>>> | |
var n1x1, n1x2, n1y1, n1y2; | |
function someFunc(navNum){ | |
ctx.moveTo(eval(navNum+'x1'), eval(navNum+'y1')); | |
ctx.lineTo(eval(navNum+'x2'), eval(navNum+'y2')); | |
// ... | |
} | |
someFunc('n1'); | |
// +++ Yes, Eval is evil, but not always, and i've not come across a better alternative to convert a string it into a var for this purpose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment