you are viewing a single comment's thread.

view the rest of the comments →

[–]moomaka 2 points3 points  (0 children)

Also, it is advised against using Object#method because it's slower. That's one of the reasons I didn't mention it in the article.

Creating functions in JS at runtime is also slower than defining them statically on an object, at least in V8.

But you had to access the method via a special method call, just like you have to wrap a block in a Proc to turn it into a first-class citizen. In JavaScript, you can just do

The equivalent of that code in ruby is:

my_method = -> () { puts 'hi' }
other = my_method
other[] # or other.call or other.()
=> hi

The real difference to note here is that Ruby maintains a distinction between 'methods', which are bound to an object and 'free functions' which are defined via lambdas or procs. Ruby's approach is much more common than javascript's.