I have a code design question. Consider the following code:
thatObj.doThis().setThat().add().update();
To allow chaining, I'm often writing return this;
, and sometimes, here or there I forget to do it, then I got an error.
In many cases, I'm not asking for a particular result (e.g. thatObj.getName()
or thatObj.getChildren()
), but instead wanting to do some updates or calling setters (e.g. thatObj.setName("foo")
or thatObj.addChild(child)
or thatObj.update()
), I was wondering if it would be more convenient to return this;
for any call of methods, I mean as a javascript default behaviour, and if not, what could be the reasons not to do so.