I have quite a problem with understanging WebWorker object in JS.
var webworker= new Worker('WI.js');
webworker.onmessage = function(e) { alert(e.data); };
webworker.postMessage('s'); // nothing is done, s is not alerted
the WI.js file is:
postMessage('t');
//self.postMessage('some');
What happens with this code is that I get an alert of t, not s. Bad thing is that I get an alert of t even if I comment webworker.postMessage('s');
Does it mean that WI.js is run at var webworker= new Worker('WI.js');?
If I uncomment second line in WI.js, I get alert 'some' and then alert 't', while I have webworker.postMessage('s'); still commented out.. I am so confused.If I write webworker.postMessage('s'); 4 times or 0 times, makes no difference and I get 'bn' then 't' and then nothing. I am so confused. How do I actualy invoke webworker correctly from main thread, and message something from webworker back?
Thanks a lot