简体   繁体   English

双下划线的目的是什么,在一个下划线之后,作为 function / class 方法的参数?

[英]What is the purpose of the double underscore, after a single underscore, as a parameter to a function / class method?

In my exploration of Polymer Dart 1.0.0, I've found for events, and observer methods, I am forced to use this pattern在我对 Polymer Dart 1.0.0 的探索中,我发现对于事件和观察者方法,我被迫使用这种模式

@reflectable
void someEvent([_, __]) {
    ...
}

or on an observer method或在观察者方法上

@Observe('someField')
void someFieldChanged([_, __]) {
    ...
}

I understand what the square brackets are for, optional parameters, I also understand that if you don't care about the passed parameters, you can represent this parameter with the underscore.我明白方括号是干什么用的,可选参数,我也明白如果你不关心传递的参数,你可以用下划线表示这个参数。 What surprised me was the examples I looked at used double underscore, __, as the second symbol between the square brackets.令我惊讶的是,我看到的示例使用双下划线 __ 作为方括号之间的第二个符号。 When I tried to use just a single underscore again, I get a duplicate formal parameter error.当我再次尝试只使用一个下划线时,我得到一个重复的形式参数错误。 Is there some reason why the second parameter you don't care about has to be different from the first?为什么您不关心的第二个参数必须与第一个不同? By this logic, if I include a third one, does it mean it'll have to be a triple underscore ___?按照这个逻辑,如果我包含第三个,是否意味着它必须是三个下划线___?

Thanks.谢谢。

Nothing special. 没什么特别的。 _ as __ as a are just variable identifiers. _ as __ as a只是变量标识符。 _ is often used to name an unused variable. _通常用于命名未使用的变量。 Here there are 2 variables unused, the first one is named _ and the second one __ . 这里有2个未使用的变量,第一个名为_ ,第二个名为__ With multiple unused variables it's common to name them _ , __ , ___ ... or _1 , _2 , _3 ... 对于多个未使用的变量,通常将它们命名为______ ...或_1_2_3 ......

In Polymer 3.0 a single underscore stands for a protected property or method and a double underscore stands for members that are private to the class.在 Polymer 3.0 中,单下划线代表受保护的属性或方法,双下划线代表 class 私有的成员。

Please take a look into this reference for more information: https://polymer-library.polymer-project.org/3.0/docs/devguide/properties请查看此参考以获取更多信息: https://polymer-library.polymer-project.org/3.0/docs/devguide/properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM