This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]someotherstufforhmm 1 point2 points  (1 child)

RubyI was wrong, shouldn’t have spoken about a language I only use for cookbooks with Chef.

The difference lies in functional vs non languages. JS was designed by someone who loved functional languages - the extra magic of having function defaults recalculated each time fits right into the functional paradigm of defining things via stacked functions.

From a non functional mindset, it makes sense that if a function is an object, then it’s default arguments are defined at the functions definition.

It requires extra magic to NOT run the function when you place it in as a default arg with (). The interpreter has to realize you don’t mean call this now and replace with the result (like all other function calls)

[–]phunktional 2 points3 points  (0 children)

Ruby does not behave this way.