A worker cannot run functions that affect the DOM.
You can only (right now) pass strings to a webworker.
What you can do is pass as much information as you can that the webworker can use, and then return what you did to the main window.
Question
I have a JS object that has a function which takes another object and an int:
this.foo.func(bar, int);
Is there a way to pass this function (and/or object) to a worker so it can execute it? Or somehow share the scope with the worker?
I'm not sure but I think Transferable Objects won't help me here since none of the objects can be translated to JSON?
La solution
A worker cannot run functions that affect the DOM.
You can only (right now) pass strings to a webworker.
What you can do is pass as much information as you can that the webworker can use, and then return what you did to the main window.
Autres conseils
You can do this with vkThread plugin.
It looks like this:
function foo(n, m) {
return n+m;
}
vkthread.exec(foo, // function to execute in a web worker
[1, 2], // arguments for the function
function(data){ // callback
console.log(data); // 3
}
);
see details at: http://www.eslinstructor.net/vkthread/