这该怎么做
function foo(x:*, ...args):* {
}
function bar(x:*, ...args):* {
foo(x, args); // how to expand args ? the args is an array now
}
Run Code Online (Sandbox Code Playgroud)
如何扩展args?当我打电话时bar(1,2,3)
,我希望它打电话foo(1,2,3)
,但它打电话foo(1,[2,3])
function bar(x:*, ...args):* {
args.unshift( x ); //add x to the front of the args array
foo.apply( <scope>, args );
}
Run Code Online (Sandbox Code Playgroud)
如果foo
和应该bar
在同一个类中声明,否则它应该是声明类的实例,如果是全局函数它应该是<scope>
this
foo
foo
null
foo.apply( this, args );
//-- or --
foo.apply( myFooInstance, args );
//-- or --
foo.apply( null, args );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
590 次 |
最近记录: |