主线程js
1 | //创建worker对象,参数为需线程执行的js文件 |
支线程new.js
1 | //监听主线程消息 |
Worker有局限性,它不能操作DOM,否则会出现如下错误,就算加进去了也是一个副本
Uncaught DataCloneError: Failed to execute ‘postMessage’ on ‘Worker’: An object could not be cloned.
1 | //创建worker对象,参数为需线程执行的js文件 |
1 | //监听主线程消息 |
Worker有局限性,它不能操作DOM,否则会出现如下错误,就算加进去了也是一个副本
Uncaught DataCloneError: Failed to execute ‘postMessage’ on ‘Worker’: An object could not be cloned.