Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2012 06:41
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Extend function prototype to run a function as a WebWorker
Function.prototype.runOnBackgroundThread = function (aCallback) {
var _blob = new Blob(['onmessage = '+this.toString()],{"type":"text/javascript"});
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob));
_worker.onmessage = aCallback;
var _test = function () {
Copy link

jdalton commented Sep 18, 2012

Neat! Be sure to check that webkitURL and others exists before attempting to access methods like createObjectURL or it will throw an error.

Copy link

doesn't work on iOS regardless both Worker, Blob, and webkitURL are there :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment