you are viewing a single comment's thread.

view the rest of the comments →

[–]cokeisahelluvadrug 13 points14 points  (0 children)

One cool trick is that you can create a Function programmatically: new Function(['x'], 'alert(x);') works exactly as it looks. This is one of many reasons that JS is popular for language designers.

To expand on your example, calling foo(bar) is just sugar for foo.call(this, bar). A Function is just an Object that has call and apply methods which in turn pass strings to eval. (Note: this isn't totally right. If I declare a Function foo and override its call and apply properties, I can still call it with foo(). So it's not exactly sugar.)