JavaScript: What is the PHP equivalent of "$ this & # 8594; $ somefunc ()"?

Is it possible to save the function name as a string in JS and call it from an object that is pretty much similar to the PHP code below?

$this->$someFunc(); 
+4
source share
2 answers
 this[someFunc](); 
+13
source

Sure. Try the following:

 var f = "foo"; var result = obj[f](); 

where foo is the method on obj , or

 this[f](); 

where foo is the method in the current instance.

+8
source

Source: https://habr.com/ru/post/1299251/


All Articles