В следующем:
<html>
<head>
<title>Worker</title>
</head>
<body>
</body>
<script >
var w = new Worker ('worker.js');
w.onmessage = function (e) {
document.body.innerHTML += '<br>' + 'WORKER : ' + e.data;
};
</script>
<script src='worker.js'></script>
</html>
worker.js вызывается как скрипт и как работник.
worker.js содержит:
var msg = 'postMessage is ' + postMessage.toString () +
', self.constructor is ' + self.constructor;
try {
postMessage (msg);
} catch (e) {
document.body.innerHTML += '<br>SCRIPT : ' + msg;
}
В рабочей среде postMessage выполняется успешно, в среде сценариев происходит сбой, потому что он либо не определен, либо в браузере требует второго аргумента.
Вывод:
хром:
SCRIPT : postMessage is function () { [native code] }, self.constructor is function DOMWindow() { [native code] }
WORKER : postMessage is function postMessage() { [native code] }, self.constructor is function DedicatedWorkerContext() { [native code] }
Firefox:
SCRIPT : postMessage is function postMessage() { [native code] }, self.constructor is [object Window]
WORKER : postMessage is function postMessage() { [native code] }, self.constructor is function DedicatedWorkerGlobalScope() { [native code] }
опера:
WORKER : postMessage is function postMessage() { [native code] }, self.constructor is function Object() { [native code] }
SCRIPT : postMessage is function postMessage() { [native code] }, self.constructor is function Object() { [native code] }
Все под Ubuntu.