任何Javascript引擎尾部调用优化? [英] Are any Javascript engines tail call optimized?

查看:128
本文介绍了任何Javascript引擎尾部调用优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Javascript实现的尾递归寻路算法,并且想知道是否有任何(所有?)浏览器可能会遇到堆栈溢出异常。

解决方案

ECMAScript 4规范最初将增加对TCO的支持,但它被放弃了。


$ b

http://lambda-the-ultimate.org/node/3047

据我所知,目前没有广泛使用的JS实现自动TCO。不过,这可能对您有用:

http://www.paulbarry.com/articles/2009/08/30/tail-call-optimization



<基本上,使用累加器模式可以达到同样的效果。


I have a tail recursive pathfinding algorithm that I've implemented in Javascript and would like to know if any (all?) browsers would possibly get stack overflow exceptions.

解决方案

The ECMAScript 4 spec was originally going to add support for TCO, but it was dropped.

http://lambda-the-ultimate.org/node/3047

As far as I know, no widely-available implementations of JS currently do automatic TCO. This may be of use to you, though:

http://www.paulbarry.com/articles/2009/08/30/tail-call-optimization

Essentially, using the accumulator pattern accomplish the same effect.

这篇关于任何Javascript引擎尾部调用优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆