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;
```
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?
On Thu, Dec 19, 2013 at 2:34 PM, Rick Waldron <[email protected]>wrote:
>
>
>
> On Thu, Dec 19, 2013 at 3:03 PM, Andrea Giammarchi <
> [email protected]> wrote:
>
>> It seems that I need to create N amount of garbage by design.
>>
>> This does not work, the const has already been defined:
>>
>> ```javascript
>> try {
>> new Proxy({},{});
>> const ES6_PROXY = true;
>> } catch(o_O) {
>> const ES6_PROXY = false;
>> }
>> ```
>>
>
> That doesn't work anyway, not because the const has already been defined,
> but because ES6_PROXY is defined within block bodies. Same as:
>
> {
> const IS_BOUND_TO_THE_BLOCK = true;
> }
>
>
>
>>
>> This does not work neither
>>
>> ```javascript
>> try {
>> new Proxy({},{});
>> var ES6_PROXY = true;
>> } catch(o_O) {
>> var ES6_PROXY = false;
>> }
>> const ES6_PROXY = false;
>>
>> // var 'ES6_PROXY' has already been declared
>> ```
>>
>
> Because the var was hoisted up to the const's scope and const can't be
> used to redeclare an existing binding of the same name. Is ES6_PROXY meant
> to be bound in the global scope?
>
>
>
>>
>> neither does the following
>>
>> ```javascript
>> try {
>> new Proxy({},{});
>> let ES6_PROXY = true;
>> } catch(o_O) {
>> let ES6_PROXY = false;
>> }
>>
>> // Illegal let declaration outside extended mode
>>
>
> That's a Canary-specific error, but the code wouldn't do what you want
> anyway, for the same reason as the first example.
>
>
>> ```
>>
>> As summary, there is no way to feature detect and define a const in the
>> same scope, a closure without the possibility to define such constant as
>> well is mandatory.
>>
>> ```javascript
>> const ES6_PROXY = function(){
>> try {
>> new Proxy({},{});
>> return true;
>> } catch(o_O) {
>> return false;
>> }
>> }();
>> ```
>>
>
> This works fine:
>
> var result = true;
> try {
> new Proxy({},{});
> } catch(o_O) {
> result = false;
> }
> const ES6_PROXY = result;
>
>
>
>
> Rick
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss