| scriptURL | string | Yes | URL of the script to be executed by the Worker thread. The script is stored in the **workers** directory, which is in the same directory as the **pages** directory of the new DevEco Studio project. If the **workers** directory does not exist, you need to create it.|
| scriptURL | string | Yes | URL of the script to be executed by the worker thread.<br>In the FA or stage model, DevEco Studio creates a **Worker** project in either of the following scenarios:<br>(a) The **workers** directory is at the same level as the **pages** directory.<br>(b) The **workers** directory is at a different level from the **pages** directory.
| options | [WorkerOptions](#workeroptions) | No | Options that can be set for the **Worker** instance. |
**Return value**
...
...
@@ -62,11 +63,68 @@ A constructor used to create a **Worker** instance.
**Example**
```
```js
// Create a worker thread.
// In the FA model, the workers and pages directories are at the same level.
// scriptURL—— Description of "entry/ets/workers/worker.ts".
// entry is the value of the name attribute under module in the module.json5 file.
// ets indicates the programming language in use.
```
Depending on whether the works and pages directories are at the same level, you may need to configure the **buildOption** attribute in the **build-profile.json5** file.
(1) If the workers and pages directories are at the same level, the configuration is optional.
In the FA model:
```json
"buildOption":{
"sourceOption":{
"workers":[
"./src/main/ets/MainAbility/workers/worker.ts"
]
}
}
```
In the stage model:
```json
"buildOption":{
"sourceOption":{
"workers":[
"./src/main/ets/workers/worker.ts"
]
}
}
```
(2) If the workers and pages directories are at different levels, the configuration is mandatory.