lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 6 September 2011 19:13, troy wreford <troywreford@gmail.com> wrote:
> I'm looking to learn javascript better too. What do you guys miss most from
> Lua when doing javascript programming?  Metatables? Consistency?
>

1) Proper lexical scoping. I was hit by this bug in a real app
recently (despite knowing JS's scoping rules):
http://p.zash.se/SVpl9w.txt (that example works with node.js, replace
sys.puts() with console.log() or whatever environment you want to test
with)

Many of the folk in the office couldn't say correctly what that script
prints when I polled them. They more often guessed it printed out what
the literal Lua translation prints out.

2) I find the concept of 'this' much less clean than Lua's 'self'.
Almost every Javascript library or project has a 'bind' function to
fix a given function's concept of 'this'. I've rarely seen such a
function in Lua.

3) I can live fine without metatables in general, but Javascript is
very prototype-centric, yet makes it incredibly difficult to have one
ordinary object inherit methods from another object. Douglas Crockford
has a decent run-down of it here, though even his approach doesn't
work in all cases (I can't remember which, I hit problems when using
his solution in a real project):
http://javascript.crockford.com/prototypal.html

4) Not being able to use any object/type as a key in an object (ie.
Javascript has no equivalent of Lua tables):

   > var a = {}, b = {}, c = {};
   > a[b] = 1; a[c] = 2;
   > print(a[b]);
   Result: 2

This happens because b and c are implicitly converted to strings when
used as keys, so they both evaluate to the key "[object Object]".

And finally, a picture is worth a thousand words, though I know a
number of you here have seen it already:
https://plus.google.com/111178996415789377552/posts/RRZHnv92VEq

Regards,
Matthew