I want to do this:
var todo = "text";
$this.eval(todo).split(/\b[\s,\.-:;]*/).length;
So that this would be t开发者_JS百科he resulting function:
$this.text().split(/\b[\s,\.-:;]*/).length;
I can't figure it out...How do I do this?
var todo = 'text';
$this[todo]().split(/\b[\s,\.-:;]*/).length;
If you must have it fully dynamic, then you can simply put it all in a string and just eval() it. Something like this:
var obj_name = "text";
var eval_code = "$this."+ obj_name + "(todo).split(/\\b[\\s,\\.-:;]*/).length;";
var result = eval(eval_code);
Also, don't name your variable eval to avoid conflicts with the eval function.
Hope that helps!
精彩评论