How do method cascades work exactly in dart?

前端 未结 3 408
夕颜
夕颜 2020-12-15 05:43

As stated in the dart article:

The \"..\" syntax invokes a method (or setter or getter) but discards the result, and returns the original receiver ins

3条回答
  •  心在旅途
    2020-12-15 06:00

    You can read the article from Gilad Bracha : Method Cascades in Dart. At its ends, you will see many examples.

    See also this answer of Lasse Nielsen about operator precedence :

    It helps to think of ".." as not really an operator, but more like a scoping construct (like parentheses). It creates a new scope from the ".." to either the next "..", or the first other scope delimiter (";", ")", "}" or similar).

    Basically, a..b().c() is the same as (t){t.b().c(); return t;}(a)

提交回复
热议问题