Proposal: Object.defineProperty shorthand

Sean Eagan seaneagan1 at gmail.com
Tue May 31 11:52:44 PDT 2011


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

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.

On Thu, May 26, 2011 at 6:24 PM, Sean Eagan <seaneagan1 at gmail.com> wrote:
> On Thu, May 26, 2011 at 4:27 PM, Sean Eagan <seaneagan1 at gmail.com> 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;
>
>
> Thanks,
> Sean Eagan
>


[1] http://wiki.ecmascript.org/doku.php?id=strawman:concise_object_literal_extensions

Thanks,
Sean Eagan


More information about the es-discuss mailing list