Primitives vs. Objects, Ruby-like features

Nathan de Vries nathan at atnan.com
Tue Mar 25 23:23:08 PDT 2008


On Mon, 2008-03-24 at 19:43 -0700, Darryl wrote:
> It'd also be nice to have non-mandatory function call parens like in
> Ruby

No it wouldn't. Functions get passed around a hell of a lot more in
Javascript than they do in Ruby, which means that you'd need to rely on
something akin to Ruby's Object#method(symbol) function all the time.

> ...and to have blocks-as-objects like in Ruby. Both of these things
> make Ruby delightfully easy to read.

Would JS2 special case the last argument to a function like Ruby does?
Ruby's block syntax is nice, but it's not without its problems. Take for
instance the fact that a method *must* be defined with the last argument
prefixed by an ampersand if you'd like it to accept a block.

As you said, you could emulate the Ruby iteration pattern by doing the
following:

  Number.prototype.times = function(func) {
    for (var i = 0; i < this; i++ ) {
      func.call();    
    }
  }
  
  Number(5).times(function(){
    alert("Foo!");
  });

I don't see this as a problem, and that's coming from someone who
develops with Ruby/Rails, Javascript & Actionscript 3. If you want to
write as much as possible in Ruby, you can always go the post-processing
route.


Cheers,

--
Nathan de Vries
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 1878 bytes
Desc: not available
Url : http://mail.mozilla.org/pipermail/es-discuss/attachments/20080326/f4100157/attachment-0002.bin 


More information about the Es4-discuss mailing list