Squ*_*gs. 1 javascript reflection
var OrderDetails = function () {
var orderdetails = {};
orderdetails.doSomething = function(){
alert('do something');
};
return orderdetails;
}
Run Code Online (Sandbox Code Playgroud)
代码中的其他地方......
processMethod('doSomething')
function processMethod(strMethod)
{
// strMethod = 'doSomething';
var orderdet = OrderDetails(); //not the exact instantiation, just illustrating it is instantiated
orderdet.strMethod(); //this is the line I'm stuck with.
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过它在Javascript中的String名称来调用方法.我已经看过apply,call和eval()作为这个问题的潜在解决方案,但似乎无法使它们中的任何一个工作.对于我的特定对象场景,是否有任何关于语法的指导?