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

问题描述

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

解决方案

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


$ b



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




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引擎尾部调用优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 08:35