在dartjs中使用选项

5 dart

新手在飞镖js.好的,我理解可选参数的概念,非常类似于C#,但我不太清楚为什么以下给出它的结果:

void main() {
  print(SayInFunction('Joe', suffix : ' Sir'));
}

String SayInFunction(name, {suffix : " Junior"}) => SayHello(name + suffix);

String SayHello(name, {suffix : " Senior"}) => ('Hello $name $suffix');
Run Code Online (Sandbox Code Playgroud)

这是回报:

Hello Joe Sir  Senior
Run Code Online (Sandbox Code Playgroud)

为什么我认为它应该是错误的:

Hello Joe Sir
Run Code Online (Sandbox Code Playgroud)

PS:如果它与$符号有关,我应该如何重构SayHello函数以返回'Hello Joe Sir'?

回答:

String SayInFunction(name, {suffix : " Junior"}) => SayHello(name, suffix: suffix);
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 2

您需要致电SayHello(name, suffix: suffix);以获得所需的结果。
您有效地调用了SayHello('Joe Sir'),因为您没有提供后缀,SayHello所以采用默认值' Senior'