Syntax for non-writability and non-configurability

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Syntax for non-writability and non-configurability

Raul-Sebastian Mihăilă
I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

kai zhu

-1
as far as i'm concerned, const is a wart with surprising behavior that should have never been introduced.  best leave the wart as is rather than add more surprises.

On Jul 8, 2017 3:09 PM, "Raul-Sebastian Mihăilă" <[hidden email]> wrote:
I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

T.J. Crowder-2
On Sat, Jul 8, 2017 at 12:31 PM, kai zhu <[hidden email]> wrote:
> -1
> as far as i'm concerned, const is a wart with surprising behavior
> that should have never been introduced.  best leave the wart as
> is rather than add more surprises.

I suggest re-reading more thoroughly. The `const` has nothing to do with the suggestion, it could just as easily have been a `let`. The suggestion is about providing a means via syntax in an object initializer to do what can be done now with `Object.defineProperty`/`Object.defineProperties` (defining properties as non-writable and/or non-configurable). It has nothing to do with whether the binding the object reference is written to (if it's even written to one) is a constant or variable.

-- T.J. Crowder


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

T.J. Crowder-2
In reply to this post by Raul-Sebastian Mihăilă
On Sat, Jul 8, 2017 at 8:09 AM, Raul-Sebastian Mihăilă <[hidden email]> wrote:
I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?

Can't say I'm keen on using obscure symbols for this. I would be interested in either standard decorators for it, or another way of doing it in an object initializer, though. `Object.defineProperty` / `Object.defineProperties` is really verbose.

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

kdex
In reply to this post by Raul-Sebastian Mihăilă
What about non-enumerability?

If we had a new token for each combination of { non-writable, non-configurable,
non-enumerable }, there would have to be seven new tokens. I'm sure I'm not
the only one who'd expect some confusion.

Yes, keeping things brief is nice, but I'm not seeing a clear advantage
compared to what you would do with decorators:

```js
const obj = {
        @nonWritable
        x: 3,
        @nonConfigurable
        y: 4,
        @nonWritable
        @nonConfigurable
        z: 5
};
```

If this is simply about brevity, just alias them to something the next intern
would be afraid of:

```js
const obj = {
        @w
        x: 3,
        @c
        y: 4,
        @w
        @c
        z: 5
};
```

On Saturday, July 8, 2017 9:09:28 AM CEST Raul-Sebastian Mihăilă wrote:

> I'd like to propose the following syntax:
>
> ```js
> const obj = {
>   x:| 3, // non-writable property with value 3
>   y:] 4, // non-configurable property with value 4
>   z:} 5 // non-writable non-configurable property with value 5
> };
> ```
>
> Perhaps class fields could also use this syntax. Maybe decorators can take
> care of this but should you really need to use a decorator for something so
> basic?
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

kai zhu
In reply to this post by T.J. Crowder-2

legitimate Object.defineProperties use-case is low and obscure enough it can stay verbose.  most of the time it causes more code-maintainability issues / tech-debt than it solves.

On Jul 8, 2017 7:51 PM, "T.J. Crowder" <[hidden email]> wrote:
On Sat, Jul 8, 2017 at 8:09 AM, Raul-Sebastian Mihăilă <[hidden email]> wrote:
I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?

Can't say I'm keen on using obscure symbols for this. I would be interested in either standard decorators for it, or another way of doing it in an object initializer, though. `Object.defineProperty` / `Object.defineProperties` is really verbose.

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

T.J. Crowder-2
On Sat, Jul 8, 2017 at 1:36 PM, kai zhu <[hidden email]> wrote:

legitimate Object.defineProperties use-case is low and obscure enough it can stay verbose.  most of the time it causes more code-maintainability issues / tech-debt than it solves.

Can't agree with that opinion. But we can easily agree on not adding obscure symbols for it.

-- T.J. Crowder

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

Allen Wirfs-Brock
In reply to this post by Raul-Sebastian Mihăilă
Note that something similar was given serious consideration by TC39 for ES6 but was ultimately being rejected: http://wiki.ecmascript.org/doku.php?id=harmony:concise_object_literal_extensions 

You can probably find relevant discussions in the es-discuss archive and TC39 notes.

Allen





On Jul 8, 2017, at 12:09 AM, Raul-Sebastian Mihăilă <[hidden email]> wrote:

I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

J Decker
https://esdiscuss.org/topic/wiki-ecmascript-org

wiki.ecmascript.org hasn't been up for 2 years?  when I ping it I get no address (v4 or v6)

On Sat, Jul 8, 2017 at 10:18 AM, Allen Wirfs-Brock <[hidden email]> wrote:
Note that something similar was given serious consideration by TC39 for ES6 but was ultimately being rejected: http://wiki.ecmascript.org/doku.php?id=harmony:concise_object_literal_extensions 

You can probably find relevant discussions in the es-discuss archive and TC39 notes.

Allen





On Jul 8, 2017, at 12:09 AM, Raul-Sebastian Mihăilă <[hidden email]> wrote:

I'd like to propose the following syntax:

```js
const obj = {
  x:| 3, // non-writable property with value 3
  y:] 4, // non-configurable property with value 4
  z:} 5 // non-writable non-configurable property with value 5
};
```

Perhaps class fields could also use this syntax. Maybe decorators can take care of this but should you really need to use a decorator for something so basic?
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax for non-writability and non-configurability

Allen Wirfs-Brock

On Jul 9, 2017, at 2:44 PM, J Decker <[hidden email]> wrote:

https://esdiscuss.org/topic/wiki-ecmascript-org

wiki.ecmascript.org hasn't been up for 2 years?  when I ping it I get no address (v4 or v6)

On Sat, Jul 8, 2017 at 10:18 AM, Allen Wirfs-Brock <[hidden email]> wrote:
Note that something similar was given serious consideration by TC39 for ES6 but was ultimately being rejected: http://wiki.ecmascript.org/doku.php?id=harmony:concise_object_literal_extensions 

You can probably find relevant discussions in the es-discuss archive and TC39 notes.

Allen



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Loading...