UPDATE
This is my final, working answer:
After running this code in the console
theMethod = 'attr("id","foo")'.match(/^([^(]+)\(([^)]*)\)/);
jQuery('#post-form')[theMethod[1]].apply(jQuery('#post-form'),JSON.parse('['+theMethod[2]+']'));
The post-form element now has a new identifier, no problem at all. This works for methods that take multiple arguments, one argument, or no arguments at all. Summary:
theMethod = theInString.match(/^\.?([^(]+)\(([^)]*)\)/);
elem[theMethod[1]].apply(elem,JSON.parse('['+theMethod+']'));
What is the safest, most reliable approach I can think of, really
What are you doing DO NOT USE EVAL :
var theMethod = 'attr(\'id\')';
//break it down:
theMethod = theMethod.match(/^([^(]+)\(.*?([^)'"]+).*\)$/);
//returns ["attr('id')", "attr", "id"]
elem[theMethod[1]](theMethod[2]);//calls the method
, (, - JS), jQuery . , , :
$('#foo').attr('id') === $('#foo')['attr']('id');
, , , .
: , , - eval, .
, , ( - : , , ):
theMethod = theMethod.match(/^([^(]+)\(([^)]+)\)$/);
//["attr('id','foo')", "attr", "'id','foo'"] --> regex must now match quotes, too
elem.theMethod[1].apply(elem,JSON.parse('['+theMethod[2]+']'));
/, , (this ), , .