Clarification on function default param values

Matthew Robb matthewwrobb at gmail.com
Mon Sep 30 19:34:50 PDT 2013


var f = function(a=this){}

would transpile to something like:

var f = (function(){

function __funcHead__(){
a=this;
}
function __funcBody__(){
// do stuff
}

var a;

return function(a){__funcHead__.apply(this, arguments);return
__funcBody__.call(this)}

}());

If my interpretation is correct.


On Mon, Sep 30, 2013 at 3:51 PM, Dmitry Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

>
> On Mon, Sep 30, 2013 at 1:17 PM, Jeff Morrison <lbljeffmo at gmail.com>wrote:
>
>> So I think during the last meeting it was decided that we'd now have two
>> scopes for functions with default param values: One for head/params, and
>> one for the function body.
>>
>
> Just re-read meeting notes, OK, cool on two scopes (seems like they are
> not in the spec yet). Want to double-check though: whether it will be
> possible to transpile now to ES3? From what I've seen in the notes, the
> head-scope will be able to access `this` value of the activation, etc. Not
> sure how to transpile now. Could someone give an example of a wrapper scope
> please, and confirm whether it's transpilable now?
>
>
>
>> Was it also agreed that we'd use let-binding (vs var-binding) for the
>> default-value expressions?
>>
>> I also just wanted to clarify some of the awkward edge-case scenarios as
>> I understand them to be sure we're all on the same page:
>>
>> var x=1, y=2;
>> function foo(x=3, y=y, z=y) {
>>   return [x, y, z];
>> }
>> foo(); // [3, undefined, undefined] ? or [3, 2, 2] ?
>> foo(2); // [2, undefined, undefined];
>> foo(2, 3); // [2, u];
>> x; // 1
>> y; // 2
>>
>>
>> var x = 1, y=2;
>> function foo(x=3,y=x+1) {
>>   return [x, y];
>> }
>> foo(); // [3, 4];
>> foo(2); // [2, 4];
>> foo(2, 3); // [2, 3];
>> x; // 1
>> y; // 2
>>
>>
>> var x = 1, y=2;
>> function foo(x=3, y=(x=undefined,4)) {
>>   return [x,y];
>> }
>> foo(); // [undefined, 4]
>> foo(2); // [undefined, 4]
>> foo(2, 3); // [2, 3] ? or [undefined, 3] ?
>> x; // 1
>> y; // 2
>>
>>
>> function foo(bar=(function() { return 'param-inner'; })) {
>>   var ret = bar();
>>   function bar() {
>>     return 'body-inner';
>>   }
>>   return ret;
>> }
>> foo(); // 'body-inner'
>> foo(function() { return 'futility'; }); // 'body-inner'
>>
>
> Good examples, but in order to answer I need to see the exact structure of
> the head-scope. Because of `this` value I'm afraid it won't be static-time
> transformable or something.
>
> Dmitry
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
- Matthew Robb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130930/0bdd9946/attachment.html>


More information about the es-discuss mailing list