Cascade notation를 적용하면 기존의 코드에서 중복된 항목은 제거되고 조금더 깔끔해진 것을 확인할 수 있다.
3. Null safety
만약에 Cascade notation 를 사용할 변수에 Null safety가 필요하다면 아래와 같이 적용할 수 있을것이다.
var button = querySelector('#confirm');
button?.text = 'Confirm';
button?.classes.add('important');
button?.onClick.listen((e) => window.alert('Confirmed!'));
button?.scrollIntoView();
// 아래와 같이 변경할 수 있다.
querySelector('#confirm') // Get an object.
?..text = 'Confirm' // Use its members.
..classes.add('important')
..onClick.listen((e) => window.alert('Confirmed!'))
..scrollIntoView();
마찬가지로 기존의 코드보다 변경된 코드가 중복된 코드도 사라지고 조금더 심플하게 표현된 것을 확인 할 수 있다.