There exist some concept like variables variable to print variable names or call f开发者_如何转开发unctions dynamically:
http://php.net/manual/en/language.variables.variable.php
Thanks in advance.
The closest JavaScript equivalent is bracket notation, for example:
var obj = { myMethod: function() { alert("Hello!"); } };
var func = "myMethod";
obj[func](); //equal to obj.myMethod();
You can test it out here, in JavaScript calling these two is equivalent:
object.property
object["property"];
And the latter allows you to use a variable, to get any property or method you want.
To be clear this is a JavaScript behavior, there's nothing specific to jQuery about it.
In javascript you can use a similar aproach.
$a = "hello";
$['hello'] = 'world';
$[$a];
alert($a + " " + $[$a]); // alerts "hello world"
See in jsfiddle.
精彩评论