Proposal: Object.defineProperty shorthand

Brendan Eich brendan at
Tue May 31 12:18:16 PDT 2011

On May 31, 2011, at 11:52 AM, Sean Eagan wrote:

> I still like the syntax proposed at the beginning of the thread the best.

I like # for non-configurable, ! for non-writable, and ~ for non-enumerable too. All prefixes. But not for assignment expressions as I think you showed -- only in object initialisers and classes.

> I know the concern from TC39 at the May meeting with object literal
> extensions [1] was that the syntax was "punctuation soup".  Does
> co-locating all 3 characters as a single prefix help with this?  I
> think it would have to be single characters for each attribute, if you
> use the full names you are hardly gaining enough conciseness to make
> it worthwhile.

Agreed. We've swerved from a verbose proposal at the March meeting, where Allen gamely tried to reuse existing keywords, then generalized and regularized to spell everything out; back to the terse punctuator approach we saw at May, but with := after the property name for read-only.

Using prefixes only seems strictly better than !~ before and := after. Also, using # for non-configurability lines up with hash-arrows or hash-functions as frozen/joined, records, and tuples. Although in your proposal # means only non-configurable, not also non-writable.

A Unix-y (ls(1) inspired) mid-point might be to use strings:

var foo = {
  {"!c!e!w"} high_integrity: 42,

or even

var foo = {
  {"!(cew)"} high_integrity: 42,

but now there's a little language encoded in the string. We would need some rules to future-proof the design. At least this would be more concise than the most-verbose proposal.

My view is that there's no middle way. We should take the punctuation soup hit, using the right punctuators, to make up for the verbosity tax of ES5's property descriptors. # for !c, ~ for !e, and ! for !w seem best at the moment.

This is surely a bikeshedding opportunity but it's also all about user interface. Warm up your paint-sprayers!


> On Thu, May 26, 2011 at 6:24 PM, Sean Eagan <seaneagan1 at> wrote:
>> On Thu, May 26, 2011 at 4:27 PM, Sean Eagan <seaneagan1 at> wrote:
>>> Something similar could work for properties, need to think about it.
>> Here's a start:
>> // reusable descriptor
>> var allFalse = {configurable: false, writable: false, enumerable: false};
>> var foo = {
>>  {configurable: false} @ a: 1, // writable, enumerable default to true
>>  allFalse @ b: 2, // dynamic
>>  #!~ @ c: 3 // shorthand still works,
>>  # @ get x() {return "x"}
>>  set x() {return "x"} // only specify for get xor set, not both
>> }
>> // property assignment versions
>> {configurable: false} @ foo.d = 4
>> allFalse @ foo["e"] = 5;
>> #!~ @ foo.f = 6;

P.S. these are not good ideas. The first two would entail restricted productions that are too close to erroneous input today, where adding a newline triggers ASI and removes the error.


>> Thanks,
>> Sean Eagan
> [1]
> Thanks,
> Sean Eagan
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list