it's not invalind, it's what I am talking about.
There is no way to conditionally define constants if not through an inline
ternary or a returned value from a closure otherwise, by design, a second
variable (garbage, pointless hoisting pollution) is mandatory.
The only way to avoid this is to evaluate ... it looks dirty, it works "as
I would like to" ... as any other C like language I know would do with
constants without the old var hoisting problem.
```javascript
try {
new Proxy({},{});
eval('const ES6_PROXY=true');
} catch(nope) {
eval('const ES6_PROXY=false');
}
console.log(ES6_PROXY);
```
Does this make sense?
On Thu, Dec 19, 2013 at 3:50 PM, Rick Waldron <[email protected]>wrote:
>
>
>
> On Thu, Dec 19, 2013 at 6:18 PM, Andrea Giammarchi <
> [email protected]> 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:
>
> if (1) {
> static int const A_VAL = 1;
> }
> printf("%d", A_VAL);
>
> // error: use of undeclared identifier 'A_VAL'
>
> JS:
>
> if (1) {
> const A_VAL = 1;
> }
> console.log(A_VAL);
>
> // 'A_VAL' is undefined
>
>
> Rick
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss