Andrea Giammarchi (2013-12-20T20:33:08.000Z)
I am suggesting that const should:

   1. reserve the const name for the whole scope (similar to var)
   2. if assigned, keep that value and throw if re-assigned
   3. if not assigned, having the very first assignment "seal the deal" and
   throw to any other re-assignment attempt

In JS code, so we get eventually rid of that silly C example I put on the
plate, a const in the global scope should be like the following, but the
logic should be per scope and not per context.

```javascript
Object.defineProperty(window, 'NAME', {
  configurable: true,
  get: function () {
    return void 0;
  },
  set: function (value) {
    Object.defineProperty(this, 'NAME', {value:value});
    // eventually with a getter instead and a setter
    // that instantly throw Errors
  }
});
```

*However*
I would rather improve try/catch so that const are easier to assign as
these are now, without forgetting as Brendan said about the value, and many
other handy situations might be solved without needing to create garbage
around the try/catch

I've realized indeed thanks to Andreas hint that the problem about creating
garbage around a constant assignment is rather about the current try/catch
implementation and the fact it does not work inline as expression.

As summary: forget const, please improve the try/catch ... this will make
life easier in many situations

Best Regards









On Fri, Dec 20, 2013 at 11:25 AM, Dean Landolt <dean at deanlandolt.com> wrote:

>
>
>
> On Fri, Dec 20, 2013 at 2:14 PM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
>> This is not helping ... yeah, apples-to-orange, as you wish .. now to
>> imagine you have a flexible understanding of the issue and the example I
>> was proposing so that:
>>
>> if (stuff) {
>>   const WHATEVER = 1;
>> } else {
>>   const WHATEVER = 2;
>> }
>>
>> two blocks, one const assigned with possibly only one value
>>
>> Now tell me again how this works in C ...
>>
>
> As written above this couldn't possibly work in C -- const is block level,
> right? Originally you wrote this with #ifdefs, which aren't blocks. This
> isn't even close to apples-to-apples.
>
> So are you suggesting that js grow a preprocessor? That block scoping
> shouldn't *really* mean block scoping? Or that const shouldn't *really*mean const? Best I can tell it could only be one of those three -- and they
> all sound bad to me.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131220/e1d69fe9/attachment.html>
domenic at domenicdenicola.com (2014-01-06T13:51:35.634Z)
I am suggesting that const should:

   1. reserve the const name for the whole scope (similar to var)
   2. if assigned, keep that value and throw if re-assigned
   3. if not assigned, having the very first assignment "seal the deal" and
   throw to any other re-assignment attempt

In JS code, so we get eventually rid of that silly C example I put on the
plate, a const in the global scope should be like the following, but the
logic should be per scope and not per context.

```javascript
Object.defineProperty(window, 'NAME', {
  configurable: true,
  get: function () {
    return void 0;
  },
  set: function (value) {
    Object.defineProperty(this, 'NAME', {value:value});
    // eventually with a getter instead and a setter
    // that instantly throw Errors
  }
});
```

*However*
I would rather improve try/catch so that const are easier to assign as
these are now, without forgetting as Brendan said about the value, and many
other handy situations might be solved without needing to create garbage
around the try/catch

I've realized indeed thanks to Andreas hint that the problem about creating
garbage around a constant assignment is rather about the current try/catch
implementation and the fact it does not work inline as expression.

As summary: forget const, please improve the try/catch ... this will make
life easier in many situations