[suggestion] @chainable decorator for functions
Closed this issue · 4 comments
darkyen commented
Chaning is a common pattern I was wondering what stops from a method for creating chainables ?
Example
class Foo{
@chainable
bar(){
}
baz(){
}
}
const f = new Foo();
f.bar().bar().bar().baz();
jayphelps commented
IMO just using return this;
is more idiomatic. Thoughts on why a decorator would be an improvement? Wouldn't it be confusing because someone could write return somethingElse;
but all return values would effectively be silently thrown away?
class Foo {
bar() {
return this;
}
baz() {
}
}
const f = new Foo();
f.bar().bar().bar().baz();
gig177 commented
I agree with jayphelps. What does improve this decorator?
darkyen commented
@jayphelps maybe I just liked using a decorator a little more. No other helpfullness.
Personally @chainable
would simply make it obvious that a function is chainable, Also when using @chainable
you explicitely expect no return