There exist some concept like variables variable to print variable names or call functions dynamically:
http://php.net/manual/en/language.variables.variable.php
Thanks in advance.
-
2Jquery isn't a language, it's a library. Javascript (EcmaScript) is the language.Topera– Topera2010年09月16日 02:05:27 +00:00Commented Sep 16, 2010 at 2:05
-
This question is similar to: Is there a JavaScript equivalent of PHP’s "variable variables"?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.dumbass– dumbass2024年10月10日 10:06:45 +00:00Commented Oct 10, 2024 at 10:06
2 Answers 2
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.
answered Sep 16, 2010 at 2:06
Nick Craver
631k138 gold badges1.3k silver badges1.2k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js