TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

By example: Continuation-passing style in JavaScript

62 点作者 budu超过 14 年前

6 条评论

nix超过 14 年前
What the author is missing: tail recursion in constant space is an implicit requirement for practical use of CPS transformations. In fact this is probably the single biggest reason for wanting efficient tail calls in a language.<p>ECMA doesn't require efficient tail recursion. Caveat programmer.
评论 #1887432 未加载
评论 #1887521 未加载
评论 #1887431 未加载
tomn超过 14 年前
Twisted (a python asynchronous network programming framework) does something similar, but inverted. Twisted functions return a Deferred object without blocking. A Deferred is a promise of a value, so rather than passing the callback into the function, you register a callback with the deferred, and the function promises to call it later.<p>This type of thing has a few nice properties -- you can easily register more than one callback, as well as using them as a pipeline (kind-of like monads in haskell), which are awkward to implement with callbacks.<p>As an aside, in python you can trick generators into turning synchronous-looking code into asynchronous, which can actually make things look a lot neater if done properly -- i'll provide code if anyone's interested.
评论 #1887877 未加载
ajro超过 14 年前
Could someone explain how the 'call/cc in javascript' from the article is supposed to be used?<p><pre><code> function callcc (f,cc) { f(function(x,k) { cc(x) },cc); }</code></pre>
评论 #1887945 未加载
ximeng超过 14 年前
People interesting in this article might also like Eric Lippert's articles on the subject.<p><a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/21/continuation-passing-style-revisited-part-one.aspx" rel="nofollow">http://blogs.msdn.com/b/ericlippert/archive/2010/10/21/conti...</a><p>They're more from a language design perspective rather than the more practical article here.
agscala超过 14 年前
Basically, this article is just about what callbacks are and how they are all nice and convenient?
评论 #1887326 未加载
评论 #1887314 未加载
评论 #1887280 未加载
zackattack超过 14 年前
doesn't jquery already do this with $.post?