Andreas Rossberg wrote:
On 19 March 2012 21:13, Allen Wirfs-Brock <[email protected]
<mailto:[email protected]>> wrote:

    (Yet Another Wacky Syntax Idea)

    Here is a relatively common coding pattern:

    var a;
    var obj = {
       get a() {return a},
       set a(v) {a=v}
    };

    Often the intent is that the variable a should only be used within
    the object literal.  The block scoping with let and do operator will
    allow the variable and object literal to be group in this manner:

    let obj  = do {
        let a;
        ({get a() {return a},
          set a()v) {a=v}
        })
    }

    Unfortunately, the object literal has to be enclosed in parentheses
    because an expression statement cannot begin with an object literal.
      The same would be the case if a function expression was involved
    rather than an object literal.


How about reusing 'new'?

let obj  = do {
    let a;
    new {
       get a() {return a},
       set a()v) {a=v}
    }
}

Or let. We may allow let have object literals in list of assignments and return the last item. So "local var for obj literal" scenario could be:

let obj  = do {
    let a, {
       get a() {return a},
       set a(v) {a=v}
    }
}

And you could write it is one-liner expressions like:

  let accumulator = let a = 0, { add (x) { return a+=x; } };

/Andreas

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

Reply via email to