3

I'm doing something like this:

new A()
  ..methodA()
  ..methodB()
  .toString();

Should this return the result of toString()? Currently it's returning the new A object.

Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112

1 Answers1

5

In your code toString() is applied on the result of methodB(). It's like you are doing :

var func = (o) {
  o.methodA();
  o.methodB().toString();
  return o;
};
func(new A());

To do what you want, you have to do something like :

(new A()
  ..methodA()
  ..methodB()).toString();
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132