
上QQ阅读APP看书,第一时间看更新
The cascade notation
We've seen that Dart provides the dot notation to access a class member. In addition to that, we can also use the double dot/cascade notation, syntactic sugar, which allows us to chain a sequence of operations on the same object:
main() {
Person somePerson = new Person()
..firstName = "Clark"
..lastName = "Kent";
print(somePerson.getFullName()); // prints Clark Kent
}
The result is the same as when employing the typical approach. It's just a good way to write succinct and legible code.
The cascade syntax works by getting the first expression return value ( new Person(), in this case) and always operates in this value, ignoring the next expression return values.
Next, we are going to delve deeper as regards each of the class components mentioned previously to understand how they can be used to extend a class to all of our needs.