How to write recursive function in MoonScript?

192 views Asked by At

Is there something like arguments.callee of JavaScript for MoonScript?

1

There are 1 answers

0
Paul Kulchenko On BEST ANSWER

Since Moonscript functions are defined as local func; func = function() end, they are all recursive. This will print 120:

recursive = (n) -> return n > 1 and n*recursive(n-1) or 1
print recursive 5

As far as I know, there is no arguments.calee alternative, but I haven't seen cases where I'd need it either. Even Mozilla's docs say "there are nearly no cases where the same result cannot be achieved with named function expressions" about arguments.callee.