Skip to content

Instantly share code, notes, and snippets.

@andyfowler
Created May 11, 2010 15:47
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 andyfowler/397454 to your computer and use it in GitHub Desktop.
Save andyfowler/397454 to your computer and use it in GitHub Desktop.
var className = 'Graph' + type;
// lesser of two uglies?
var graph = new window[className](this);
// versus
var graph = eval('new ' + className + '(this)');
// using window makes sanity checking easier:
if (typeof window[className] === 'function') // instantiate ...
// versus
if (eval('typeof ' + className) === 'function') // instantiate ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment