James Hurford
James Hurford

Reputation: 2058

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

@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.

Upvotes: 9

Views: 2100

Answers (2)

Jorge-cruz-Dev
Jorge-cruz-Dev

Reputation: 1

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.

Please take a look into this reference for more information: https://polymer-library.polymer-project.org/3.0/docs/devguide/properties

Upvotes: -1

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76193

Nothing special. _ as __ as a are just variable identifiers. _ is often used to name an unused variable. Here there are 2 variables unused, the first one is named _ and the second one __. With multiple unused variables it's common to name them _, __, ___ ... or _1,_2,_3...

Upvotes: 13

Related Questions