Any way to get the return value of last method in cascade?

107 Views Asked by At

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.

1

There are 1 best solutions below

0
Alexandre Ardhuin On BEST ANSWER

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();