javascript - How to execute string containing function name AND parameters? -


in javascript, have string this:

"dosomething('param1','param2')" 

and want execute it. aware use

window['dosomething']('param1', 'param2'); 

but works if function name separate arguments. in case combined. think can use eval() consensus seems should avoided. there way?

edit: answer request more info: using string this:

<a id="yesbutton" onclick="closemodalview_yes("dosomething('param1','param2')")"> 

where closemodalview_yes close modal yes/no window , execute given function, although @ times may pass dosomethingelse(param1) takes 1 parameter.

use eval, like:

eval( "console.log( 'hey', 'here am' )" ); 

however eval pretty dangerous , it's not recommended.

if can (still don't have info case), render javascript between <script> tags in template, making "regular code", easier debug.

also practice pass data (i.e. json) rather code. try rethinking logic or provide additional information.


Comments

Popular posts from this blog

c++ - End of file on pipe magic during open -

basic authentication with http post params android -

data.table making a copy of table in R -