Javascript 从字符串动态调用对象方法
2022-08-30 05:29:32
是否可以动态调用将方法名称作为字符串的对象方法?我会想象它是这样的:
var FooClass = function() {
this.smile = function() {};
}
var method = "smile";
var foo = new FooClass();
// I want to run smile on the foo instance.
foo.{mysterious code}(); // being executed as foo.smile();