app = {
echo: function(txt) {
alert(txt)
},
start: function(func) {
this.func('hello');
}
}
app.start('echo');
Run Code Online (Sandbox Code Playgroud)
我需要调用作为func传递的任何函数.怎么做?这个例子对我不起作用.
用this[func]而不是this.func
app={
echo:function(txt){
alert(txt)
},
start:function(func){
this[func]('hello');
}
}
app.start('echo');
Run Code Online (Sandbox Code Playgroud)