Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Created September 11, 2012 06:44
Show Gist options
  • Save jameswomack/3696530 to your computer and use it in GitHub Desktop.
Save jameswomack/3696530 to your computer and use it in GitHub Desktop.
test
var InlineWorker = function (theWorkerFunction,aCallback) {
var _blob = new Blob(['onmessage = '+theWorkerFunction.toString()],{"type":"text/javascript"});
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob));
_worker.onmessage = aCallback;
this.postMessage = function(){_worker.postMessage.apply(_worker,Array.prototype.slice.call(arguments))};
return this;
}
var _inlineWorkerCode = function(e) {
//put anything that doesn't use window or document here
postMessage(Object.keys(e.data)[0]);
postMessage(e.data.dude);
}
new InlineWorker(_inlineWorkerCode, function(e){
alert(e.data);
}).postMessage({dude:"where's my car?"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment