I prefer passing variables with wp_localize_script
.
$array['theme_url'] = template_directory_uri();
wp_localize_script( 'enqueue_handle', 'variable', $array);
Then access the variable with variable.theme_url in the javascript.
http://codex.wordpress.org/Function_Reference/wp_localize_script