Created
September 11, 2012 06:44
-
-
Save jameswomack/3696530 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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