Rick Waldron (2013-12-19T23:50:16.000Z)
domenic at domenicdenicola.com (2014-01-06T13:47:47.007Z)
On Thu, Dec 19, 2013 at 6:18 PM, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote: > Rick thanks but I wasn't strictly asking for solutions because I have one, > I was rather pointing at the fact that there is no solution and by design > we need to create garbage. > > Your last example talks itself ... why do we need to define another > variable in that scope? That is annoying, imho ... I don't want define a > `tmp` like variable per each const type I'd like to address down the road, > you know what I mean? > > I cannot even drop that var, so that's a potential leak in the global > scope/context if not loeaded through modules while I might want to define > that constant globally (and maybe name-spaced, but that's not the issue > here) > > IE11 ... I don't have it with me now, would this work nicely ? I think no > :-( > > ```javascript > let ES6_PROXY = true; > try { > new Proxy({},{}); > } catch(o_O) { > ES6_PROXY = false; > } > const ES6_PROXY = ES6_PROXY; > ``` It doesn't matter if I ran this in IE11 today or Firefox/Chrome/whatever when those implementations are updated: let and const bindings don't allow _redeclaration_ of bindings that already exist in that scope. > So const are not as simple and straight forward to be defined as it is in > C or others and because these have been defined on top of `var` hoisting > behavior. > > ```C > > #ifdef WHATEVER > static int const NAME = 1;#else > static int const NAME = 0; > > #endif > > ``` > > Thoughts? It's an invalid comparison, unless you're saying you want ifdefs in JS. This is an apples-to-apples comparison: C: ```C if (1) { static int const A_VAL = 1; } printf("%d", A_VAL); // error: use of undeclared identifier 'A_VAL' ``` JS: ```js if (1) { const A_VAL = 1; } console.log(A_VAL); // 'A_VAL' is undefined ```