Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解释 TCO - 尾调用优化(Tail Call Optimization)。 有没有支持尾调用优化的 JavaScript 引擎? #549

Open
Rashomon511 opened this issue Jul 16, 2019 · 0 comments

Comments

@Rashomon511
Copy link
Owner

尾调用(Tail Call)是函数式编程的一个重要概念,用简单的一句话描述就是“在函数的最后一步调用函数”

function f(x){
    let y=x+1;
    return g(y);
}

尾调用优化"(Tail call optimization),即只保留内层函数的调用记录。如果所有函数都是尾调用,那么完全可以做到每次执行时,调用记录只有一项,这将大大节省内存。这就是"尾调用优化"的意义。
现在还没有支持尾调用优化的 JavaScript 引擎
http://www.ruanyifeng.com/blog/2015/04/tail-call.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant