Proposal: Concise instance initialisation
Sean Eagan
seaneagan1 at gmail.com
Sat May 21 01:10:37 PDT 2011
Summary:
Update "Object Literal Extensions" [1] to integrate with constructor
parameters for concise instance initialization.
Details:
function f (a, !~this.b, this.c:= 1) {
g(a);
}
// results in f's [[Construct]] ( but not [[Call]] ) behaving like:
function f (a, b, c = 1) {
Object.defineProperty(this, "b", {configurable: false, enumerable:
false, writable; true, value: b};
Object.defineProperty(this, "c", {configurable: true, enumerable:
true, writable; false, value: c};
g(a);
}
Grammar changes to [1] :
FormalParameter :
FormalParameterPrefixOpt Identifier FormalParameterInitialiserOpt
// possibly integrate with destructuring and/or rest parameters as well
FormalParameterPrefix :
PropertyPrefixOpt thisOpt . // "this" is optional
FormalParameterInitialiser :
:Opt Initialiser
[1] http://wiki.ecmascript.org/doku.php?id=strawman:basic_object_literal_extensions
Cheers,
Sean Eagan
More information about the es-discuss
mailing list