Is this valid?

function Person(a) {
  this.age = a;
}
Person.prototype.myage = {|| this.age};

function info(myage) {

  console.log('my age is '+myage());   
}
info(new Person(10).myage);
info(new Person(12).myage);


________________________________
From: Brendan Eich <[email protected]>
To: es-discuss <[email protected]>
Sent: Sunday, May 22, 2011 9:17 PM
Subject: block lambda revival, now with semantics


http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival

Only a couple of TODOs:
11.1.7.1 [[Call]] 
When the [[Call]] internal method for a block-lambda object B is called with a 
list of arguments, the following steps are taken: 
        1. Let funcCtx be the result of establishing a new execution context 
for function code using the value of B‘s [[FormalParameters]] internal 
property, the passed arguments List args, and the this value given by the 
ThisBinding component of the execution context in B‘s [[Context]] internal 
property.
        2. Let result be the result of evaluating the StatementList or 
EmptyStatement that is the value of B‘s [[Code]] internal property.
        3. Exit the execution context funcCtx, restoring the previous execution 
context.
        4. If result.type is normal and result.value is empty then return 
(normal, undefined, empty).
        5. Else if result.type is break, continue, or return and B‘s 
[[Context]] internal property has already exited, throw a TypeError exception.
        6. Else if result.type is break or continue and result.target has 
already exited, throw a TypeError exception.
        7. Else return the Completion value result.
TODO: forbid var in block-lambdas (yeah!)
11.2.3 Function Calls 
... 
TODO: Process Completion return type 
The production CallExpression: CallExpression[no LineTerminatorhere] 
BlockArguments is evaluated evaluated in exactly the same manner, except that 
BlockArguments is evaluated instead of Arguments in step 3. 

In other words, a block-lambda's [[Call]] internal method must return a 
Completion in order to attempt to break, continue, or return in the enclosing 
switch/loop/function. One way to do this: uncatchable internal Completion 
exceptions for (break, empty, target), (continue, empty, target), and (return, 
value, empty) thrown by the relevant statements. The uncatchable part is ugly 
and this looks like an unnecessary change at the statement-grammar level, since 
Completion type works there already to solve the same problem.

The issue is that within an expression, results are values, not Compietions. 
There's a bit of magic in the spec by which an exception thrown from 
sub-expression evaluation is caught by the statement level and packaged up into 
a (throw, value, empty) completion. Block-lambdas are the first way by which an 
expression can complete with break, continue, or return.

We could make all expression evaluation in the spec return a union of Reference 
and Completion types. Explicitness seems best. I'll let this one marinate.

The first TODO proposes to ban var from occurring within block-lambdas. This 
seems better than contorting the spec to hoist var bindings across block-lambda 
boundaries. Who is with me? ;-)

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

Reply via email to