开发者

C#-like named argument in javascript?

Is it possible to use named argument in javascript?

E.g.

开发者_如何学Python

void method (int a, int b);

method(a:1, b:2);


In javascript you could do this:

function method(foo) {
    // use foo.a and foo.b here    
}

and then call it like this:

method({ a: 1, b: 2 });


I believe the answer is 'no', but you can come to an approximation by using a single object with names properties/members as the argument to your functions. See here for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜