On Sat, May 21, 2011 at 6:39 PM, Brendan Eich <bren...@mozilla.com> wrote:

> Really, we're between these choices:
>
> 1. Do nothing, function + return 4ever.
>
> 2. Shorter function syntax by some abbreviation for 'function' that still
> requires 'return ' followed by an expression to return a value.
>
> 3. Block-lambdas.
>
> Some on the committee are enthusiastic about 3. 2 is warm beer and not
> going anywhere fast, least of all with # (a misuse of that punctuator, which
> is wanted for other purposes). 1 is lame.
>

Isn't there also:

4. Shorter function syntax that allows a single expression body which
doesn't require return, but *if it has* a return, it retains the same
semantics as current JS functions.

That was my understanding of how -> functions would work:

log(-> 'hi')()) // 'hi', no return required.

function foo() {
  let bar = (-> { return 'bar'; })();
  return 'not bar';
}

log(foo()); // 'not bar'


Isn't that what the current proposal is? I'm not arguing for or against
this, just trying to understand our options.

Personally, I'm having trouble figuring out what my opinion is on how return
(et. al.) should act inside a block lambda. I can see it making sense either
way:

function sortByName(people) {
  people.sort {|a, b|
    if (a.name == b.name) return 0;
    if (a.name < b.name) return -1;
    return 1;
  }
}

function findProperty(path, property) {
  File.open(path) {|file|
    for (let line in file) {
      let [name, value] = line.split('=');
      if (name == property) return value;
    }
  }
}


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

Reply via email to