JavaScript和线程 [英] JavaScript and Threads

查看:166
本文介绍了JavaScript和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在JavaScript中进行多线程?

Is there some way to do multi-threading in JavaScript?

推荐答案

参见 http://caniuse.com/#search=worker 获取最新的支持信息。

See http://caniuse.com/#search=worker for the most up-to-date support info.

以下是大约2009年的支持状态。

The following was the state of support circa 2009.

你要google的词汇 JavaScript工作线程

The words you want to google for are JavaScript Worker Threads

除了 Gears 之外,目前还没有什么可用,但有很多关于如何实现这一点的讨论所以我想看看这个问题,因为将来无疑会改变答案。

Apart from from Gears there's nothing available right now, but there's plenty of talk about how to implement this so I guess watch this question as the answer will no doubt change in future.

以下是Gears的相关文档: WorkerPool API

Here's the relevant documentation for Gears: WorkerPool API

WHATWG有一份关于worke的建议草案r个主题:网络工作者

WHATWG has a Draft Recommendation for worker threads: Web Workers

还有Mozilla的 DOM工作者主题

And there's also Mozilla’s DOM Worker Threads

更新: 2009年6月,JavaScript线程浏览器支持的当前状态

Update: June 2009, current state of browser support for JavaScript threads

Firefox 3.5 有网络工作者。一些网络工作者的演示,如果你想看到他们在行动:

Firefox 3.5 has web workers. Some demos of web workers, if you want to see them in action:

  • Simulated Annealing ("Try it" link)
  • Space Invaders (link at end of post)
  • MoonBat JavaScript Benchmark (first link)

Gears插件也可以安装在Firefox中。

The Gears plugin can also be installed in Firefox.

Safari 4 WebKit nightlies 有工作线程:

  • JavaScript Ray Tracer

Chrome 已启动Gears,因此可以执行thr eads,虽然它需要来自用户的确认提示(并且它使用与Web工作者不同的API,尽管它可以在安装了Gears插件的任何浏览器中使用):

Chrome has Gears baked in, so it can do threads, although it requires a confirmation prompt from the user (and it uses a different API to web workers, although it will work in any browser with the Gears plugin installed):


  • Google Gears WorkerPool演示(这不是一个很好的例子,因为它在Chrome和Firefox中运行速度太快,虽然IE运行速度足够慢,看不到阻止交互)

  • Google Gears WorkerPool Demo (not a good example as it runs too fast to test in Chrome and Firefox, although IE runs it slow enough to see it blocking interaction)

IE8 IE9 只能安装Gears插件的线程

IE8 and IE9 can only do threads with the Gears plugin installed

这篇关于JavaScript和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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