-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New syntax proposal: Constructor Cascade (returns the cascadee) #172
Comments
I have to agree that a cascade expression should evaluates to the cascadee value. While maximally minimal, the current syntax seems to miss the major use cases by limiting itself to the top-level. We add no new keywords as a policy, so we may have to introduce some new symbol operator. Say,
And/or we can make
|
Hmm, is it even worth keeping Using For the times that you do need to set the context for an IEFE, you could just special-case |
Great point. The purpose of So the proposal becomes:
|
That looks fine to me, though the readability of the compiled js suffers a bit with the comma expression. Similar to #115, it'd be nicer if it compiled to head.appendChild(
(x$ = document.createElement('title')
, x$.textContent = btitle
, x$)) Just a minor issue. |
I've got a fair amount of code that looks like this:
or more purely, like this:
where some of the code initializes and mutates an object just to pass it into another function (or return it). When available, I usually use a full constructor:
But some constructors, e.g. DOM
Image
, have stupid arguments (nosrc
), so an extra line of initialization is necessary.I know I can use
new
with a block to create thenew function() {...}
form, but that doesn't work withImage
, and it introduces overhead. Thus, my straw man is:Constructor Cascade
Similar to cascade, but expression returns the original reference (after execution of the block) instead of the result of the last expression in the block.
=>
Advantages
return this
at the end of a function, e.g. when usingwith new XMLHttpRequest
$(body).append($('<p>').text('just look at all this overhead!'))
Problems
construct
The text was updated successfully, but these errors were encountered: