最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Web workers and accessing object attached to the window object - Stack Overflow

programmeradmin3浏览0评论

I have an ember application that I create like this:

window.App = Ember.Application.create({});

I want to do some background processing on a web worker.

How can I get access to the window object or some other global object in the separate web worker thread?

I have an ember application that I create like this:

window.App = Ember.Application.create({});

I want to do some background processing on a web worker.

How can I get access to the window object or some other global object in the separate web worker thread?

Share Improve this question edited Jun 8, 2012 at 9:06 dagda1 asked Jun 8, 2012 at 8:47 dagda1dagda1 28.8k67 gold badges255 silver badges477 bronze badges 4
  • Can you use postMessage() to send state back? – alex Commented Jun 8, 2012 at 8:49
  • I can but does that not pass context back to the main thread? – dagda1 Commented Jun 8, 2012 at 8:54
  • 1 Yeah. From what I can gather, you're supposed to do things on a new thread with no immediate side effects on the main thread. – alex Commented Jun 8, 2012 at 8:57
  • What I am trying to do is load an object with json and have it available later. Should I put the data into local storage as trying to update the store on the new thread has side effects. – dagda1 Commented Jun 8, 2012 at 8:58
Add a comment  | 

1 Answer 1

Reset to default 20

Short answer. You can't.

The only resources available to web workers are that which they load from JavaScript files using importScripts() or anything that is passed to them via postMessage().

You can however now pass Objects to them. They are serialized and de-serialized to JSON automatically.

Also, there is no access to local storage from the Worker.

发布评论

评论列表(0)

  1. 暂无评论