Last active
March 14, 2016 15:26
-
-
Save mattcodez/3f62cc03aabd651ffbd2 to your computer and use it in GitHub Desktop.
Proposal for temporary scope variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Proposal for temporary scope variables | |
let result = something.crazy.long.bar ? something.crazy.long.bar() : something.crazy.long.other(); | |
//with() - Not 'strict' compliant | |
with (something.crazy.long){ | |
result = bar ? bar() : other(); | |
} | |
//fat arrow function | |
result = (a => a.bar ? a.bar() : a.other())(something.crazy.long); | |
//extra variable | |
let a = something.crazy.long; | |
let result = a.bar ? a.bar() : a.other(); | |
//cleanest, but pollutes namespace, so... | |
let result; | |
{ | |
let a = something.crazy.long; | |
result = a.bar ? a.bar() : a.other(); | |
} | |
//proposal | |
//scope good only for a single statement, variable names can't be defined | |
let result = something.crazy.long -> _1.bar ? _1.bar() : _1.other(); | |
//To avoid implicit variables, another option: | |
let result = something.crazy.long{label} label.bar ? label.bar() : label.other(); | |
//result of expression temporarily stored | |
//old | |
let result = (someArr.length * 20 > 40) && someArr.length * 20; | |
//var store | |
let result; | |
{ | |
let temp = someArr.length * 20; | |
result = temp > 40 && temp; | |
} | |
//proposal | |
//idea: implicitly return var if -> returns true | |
let result = (someArr.legnth * 20) -> (_1 > 40); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment