Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Created April 26, 2013 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustintheweb/5468690 to your computer and use it in GitHub Desktop.
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
// >> 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