Skip to content

Instantly share code, notes, and snippets.

@jed
Created April 9, 2011 09:41
Show Gist options
  • Save jed/911277 to your computer and use it in GitHub Desktop.
Save jed/911277 to your computer and use it in GitHub Desktop.
a function that takes code and returns a list of variable names needing declaration
var getVars = function( dummy, err, re ) {
try { eval( dummy ) } catch( e ) { err += e }
re = new RegExp( "^" + err.replace( dummy, "(\\w+)" ) + "$" )
return function( code ) {
var args = []
, name
while ( 1 ) {
try { Function.apply( Function, args.concat( code ) )() }
catch( e ) {
name = ( re.exec( e ) || [] )[ 1 ]
if ( !name ) throw e
args.push( name )
continue
}
return args
}
}
}( "_" + Date.now(), "" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment