是否可以在JS中将函数的名称存储为字符串,并从对象中调用它,就像下面的PHP代码一样?
$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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.