开发者

JavaScript: What is the equivalent of PHP's "$this->$somefunc()"?

Is it possible to stor开发者_开发问答e the name of a function as string in JS, and invoke it from an object, pretty much like the PHP code below?

$this->$someFunc();


this[someFunc]();


Sure thing. Try this:

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

where foo is a method on obj, or

this[f]();

where foo is a method on the current instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜