start | find | index | login or register | edit
Montag, 12. April 2010 link aYago

I've long maintained that JavaScript is a rather peculiar language when it comes down to core language semantics. Inspired by a few hours of discussion and exploration with Chris Langreiter, here's a little example:

function foo() {                     function bar() {
var f = function() 42; function f() 4711;
function f() 4711; var f = function() 42;
return f; return f;
} }

What do you think, does foo()() === bar()() hold? Would you expect it to? Would you want it to (say, if you were the one defining the semantics)?

Kragen Javier Sitaker 3850 days ago:
I was surprised that the body of a function could be a statement that wasn't a block!

Yes, the hoisting-the-function-statement-to-the-top behavior is sucky and counterintuitive.

earl 3849 days ago:
The "short-hand function bodies" are JavaScript 1.8's "expression closures", a really nice feature, if you ask me (and only available in Mozilla JS engines at the moment, if I'm not mistaken).

Kragen Javier Sitaker 3840 days ago:
It is a really nice feature, and I suppose I should have realized that it wasn't a statement. However, the syntax was a little fragile, as I recall.

Please log in (you may want to register first) to post comments!

powered by vanilla
echo earlZstrainYat|tr ZY @. • esa3 • online for 7204 days • c'est un vanilla site