Is there a way to provide named parameters in a function call in JavaScript?

前端 未结 10 1859
抹茶落季
抹茶落季 2020-11-22 07:28

I find the named parameters feature in C# quite useful in some cases.

calculateBMI(70, height: 175);

What can I use if I want this in JavaS

10条回答
  •  天涯浪人
    2020-11-22 07:45

    If you want to make it clear what each of the parameters are, rather than just calling

    someFunction(70, 115);
    

    why not do the following

    var width = 70, height = 115;
    someFunction(width, height);
    

    sure, it's an extra line of code, but it wins on readability.

提交回复
热议问题