On 19 March 2012 21:13, Allen Wirfs-Brock <[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}
}
}
That is, in 11.2.2, semantics of "new NewExpression", simply replace step 4
with
4. If constructor does not implement the [[Construct]] internal method,
return constructor.
(Instead of throwing a TypeError. Probably want to rename 'constructor'
there.)
AFAICS, a plain object literal never has [[Construct]], so this should
always work. Strictly speaking that is a breaking change, but it seems
relatively unlikely that there is much code relying on the current error
behaviour. But maybe I'm being naive. :)
/Andreas
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss