I like jQuery's ability to method chain commands ( .animate().css() etc ) which in the backend is achieved by returning the special variable "this".
How can I implement a similar method of chaining without having to set state within my object. Take for example:
that.getHospitalCoverDataStore().findBy('short_name').withValue('sam');
This method chain queries a field in the datastore "short_name" using the value "sam". I can set an internal state to "short_name" when the first method has been called then look that up again when withValue is called. This seems like a kludge to me though, for a start I can't throw an error if withValue is called before findBy as it will reuse the last findBy setting.
How can I better implement this?