与Web Worker通信时保留对象身份

时间:2019-04-05 23:47:19

标签: javascript web-worker

将对象传递给Web Worker时,是否可以保留其身份?

// main.js
const w = new Worker('worker.js');

const data = {
  blah: 'blah'
};

// receiving from worker
w.onmessage = e => e.data === data; // <= THIS IS ALWAYS FALSE

// worker.js
onmessage = e => postMessage(e.data);

0 个答案:

没有答案