Proposal: Object.defineProperty shorthand

Sean Eagan seaneagan1 at
Thu May 26 14:27:39 PDT 2011

On Thu, May 26, 2011 at 2:57 PM, David Flanagan <dflanagan at> wrote:
> Is a not-quite-so-cryptic shorthand possible?

I tried to choose the characters to be as non-cryptic as possible
using the following mnemonic devices:

# - non-configurable:
corresponds to frozen which # represents for records, tuples etc.

! - non-writable:
It's the "NOT" operator.  The lighter weight of ! vs # matches the
lighter restriction of non-writable vs non-configurable.

~ - non-enumerable (matches Allen's original suggestion):
It's the "BITWISE NOT" operator.  One could imagine objects internally
storing a list of bits E, each of which is set if their corresponding
object property specified this mark when being created.  Then ~E
represents the list of bits corresponding to the object's enumerable

> Could you use #readonly,
> #hidden, and #fixed instead of !, ~ and #, for example?

I think it may be confusing to introduce different names for the
"non-" version of properties, thus, it would probably be better to
just use the full attribute names, however, then you would lose much
of the conciseness gained.

> This would be more extensible.

That is true, although I'm not sure what the likelihood is of any new
property descriptor attributes being added in the future?  Does anyone
have any thoughts on that?

> Maybe #sealed and #frozen for object, literals?

I've been working on a concept called "object descriptors" as the
object level equivalent of property descriptors, still working on it,
will send something out when complete.  But, for the declarative
syntax for it, I am thinking along the lines of an "annotates"
operator signified by @ :

// create a proxy
var proxy = {prototype: P, handler: H} @ {
  x: "x"

// reusable descriptor
var nonExtensibleP = {prototype: P, extensible: false};

var x = nonExtensibleP @ {
  x: "x"

Something similar could work for properties, need to think about it.

Sean Eagan

More information about the es-discuss mailing list