简体   繁体   中英

How to write recursive function in MoonScript?

是否有类似MoonScript的JavaScript的arguments.callee之类的东西?

Since Moonscript functions are defined as local func; func = function() end 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM