开发者

C#-like named argument in javascript?

开发者 https://www.devze.com 2023-03-05 10:24 出处:网络
Is it possible to use named argument in javascript? E.g. 开发者_如何学Python void method (int a, int b);

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

精彩评论

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

关注公众号