Smalltalk-like cascading
redalastor opened this issue · 8 comments
I'd like to suggest smalltalk-like cascading which I already suggested for CoffeeScript: jashkenas/coffeescript#1431 (comment)
Things to consider:
- The right syntax.
- Interaction with
?.
.=
etc. - Is our
with
insufficient enough to require this?
I think the syntax might be sth similar to .~
a.~b
=> __bind(a,a.b)
a.!b
=> __chain(a,a.b)
where we have
function __chain(me, func) {
return function() {
func.apply(this/*or `me` thinking about whether chained method must be bound?*/, arguments);
return me
}
}
Related discussion ongoing at: jashkenas/coffeescript#1495
"Expression Block" is unambiguous on top-level. Making this a with
alias gives:
document.querySelector '#eyecatch'
@style
@color = \red
@fontSize = \large
@scrollIntoView!
looks cool, but not really clear
with
semantics may seem too implicit and/or cumbersome due to the context/scope change.
Instead introducing another symbol for simple substitution for the cascade target would give:
document.querySelector '#eyecatch'
&style
&color = \red
&fontSize = \large
&scrollIntoView!
↓
var x$, y$;
x$ = document.querySelector('#eyecatch');
y$ = x$.style;
y$.color = 'red';
y$.fontSize = 'large';
x$.scrollIntoView();
Not that this should make a difference, but remember LiveScript are using &
for their arguments
shorthand. Does anyone actually use labels? Can't we pick something else for the label syntax and just use :
here?
LiveScript are using
&
for theirarguments
shorthand.
So what?
Can't we pick something else for the label syntax and just use
:
here?
Colon makes most sense for labels.
Does anyone actually use labels?
Probably more relevant as named destructuring/let
.