Summarizing the state of proposals from your discussion:

  function foo(arg1, arg2) {...} // implicit parameter/receiver 'this'

  #foo(this | arg1, arg2) {...}  // implicit parameter/receiver 'this'

  #foo( arg1, arg2) {...}    // no implicit parameter/receiver
                                         // any outer 'this' is in scope

It seems that this is painting one problem (control over 'this')
twice, (a) by making it possible to name the implicit parameter
and (b) by removing the implicit parameter unless named.

As a consequence, the advantage of having less syntactic
noise disappears for many use cases, so usage will likely
be split between the two forms:

   #(this| ..) { .. }
   function ( .. ) { .. }

If the idea is to make '#' different from 'function' in avoiding 'this' when possible, then this split makes some sense (as in: "you should not use 'this' here, but we support it in this not-so-handy form if you absolutely need it").

If the idea is to replace 'function' with something more
useable, with less syntactic noise, then why not solve it
the other way round? Optional naming of implicit parameters already gives us control over what is in scope,
so we don't have to drop 'this' by default as well:

   #( .. ) { .. } // implicit parameter 'this'
   #(_| ..) { .. } // implicit parameter '_', outer 'this' is in scope

That would mean we'd have to write more if we don't want the inner 'this', and it would mean that there always is an implicit parameter (named or not). Would that be better or worse than the current proposal?

The difference between '#' and 'function' would be smaller,
making it more likely that the former will be preferred, and
less likely that users will trip over missing 'this', but I don't know whether Javascript implementations can drop unused parameters early?

Claus

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to