未验证 提交 d0485c03 编写于 作者: O openharmony_ci 提交者: Gitee

!11744 Worker资料整改

Merge pull request !11744 from wangzhaoyong/master
......@@ -422,7 +422,7 @@ dispatchEvent(event: Event): boolean
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.dispatchEvent({type:"alert"});
workerInstance.dispatchEvent({type: "alert"});
```
......@@ -444,7 +444,7 @@ workerInstance.removeAllListener();
## ThreadWorkerGlobalScope<sup>9+</sup>
Worker线程用于与宿主线程通信的类,通过postMessage接口发送消息给宿主线程、close接口销毁Worker线程。DedicatedWorkerGlobalScope类继承[GlobalScope<sup>9+</sup>](#globalscope9)
Worker线程用于与宿主线程通信的类,通过postMessage接口发送消息给宿主线程、close接口销毁Worker线程。ThreadWorkerGlobalScope类继承[GlobalScope<sup>9+</sup>](#globalscope9)
### postMessage<sup>9+</sup>
......@@ -609,7 +609,7 @@ workerInstance.addEventListener("alert", (e)=>{
## GlobalScope<sup>9+</sup>
Worker线程自身的运行环境,WorkerGlobalScope类继承[WorkerEventTarget](#workereventtarget9)
Worker线程自身的运行环境,GlobalScope类继承[WorkerEventTarget](#workereventtarget9)
### 属性
......@@ -1401,7 +1401,7 @@ parentPort.onerror = function(e){
```js
// main.js
import worker from '@ohos.worker';
const workerInstance = new worker.Thread("workers/worker.js");
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.postMessage("message from main to worker");
workerInstance.onmessage = function(d) {
// 当worker线程传递obj2时,data即为obj2。data没有Init、SetName的方法
......@@ -1413,12 +1413,9 @@ workerInstance.onmessage = function(d) {
import worker from '@ohos.worker';
const parentPort = worker.workerPort;
class MyModel {
name:"undefined"
Init() {
this.name = "wzy"
this.age = 18
}
SetName() {
this.name = "WZY"
this.name = "MyModel"
}
}
parentPort.onmessage = function(d) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册