Эт забыл про worker
function getWorker() {
var blob;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
var mimeString = 'application/javascript';
var code = "onmessage = function(e) { postMessage('My' + e.data); }";
try {
blob = new Blob([code], {type: mimeString});
} catch (e) {
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder;
var bb = new BlobBuilder();
bb.append(code);
blob = bb.getBlob(mimeString);
}
var url = window.URL.createObjectURL(blob);
var worker = new Worker(url);
URL.revokeObjectURL(url);
return worker;
}
var worker = getWorker();
worker.postMessage('Test');
worker.onmessage = function (e) {
alert(e.data);
};
Пример Function
var fn = "function (a, b) {\
return a + b;\
}";
var call = Function('return ' + fn)();
alert(call(1, 2));