Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AN ES6 ELSE-BLOCK PROPOSAL
- ============================
- ## Syntax
- Else-Statement :=
- { Statement } else Statement
- { Statement } else { Statement }
- Each else for which the choice of associated if is ambiguous shall be associated with the nearest possible if that would otherwise have no corresponding else.
- ## Semantics
- The production { Statement } else { Statement } is evaluated as follows:
- 1. let rA be a boolean. If the first Statement was executed set rA to true. Otherwise( if the execution was blocked by an if statement) let rA be false.
- 2. if rA is true, then
- a. skip the second Statement and continue afterwards.
- 3. else,
- b. execute the second Statement.
- ## Notes
- I hope TC39 agrees that this is a valuable extension to boolean logic. This allows for much easier readable code like:
- if ( mustgotowork() ) { wakeup(); } else { sleepsomemore(); } else { brush_teeth(); } else { sleepsomemore(); } else { putclotheson() } else { wakeup(); } else { drivetowork(); } else { invitesomechicks() }
- Also, block parens are not optional for better visual highlighting.
Add Comment
Please, Sign In to add comment