Object: Worker
The Worker object represents a thread to be run in the background.
Web workers work as follows:
- On the parent web page, a script runs in the main thread of the Window object.
- The script in the main thread spawns a new thread by constructing a new Worker object. The constructor takes as an argument the JavaScript file that it is to load and execute.
- The worker executes the script.
To create a new worker thread, you need only construct a new worker object with the JavaScript file it is to load as the argument. For example:
var worker = new Worker(workerScript.js)
Worker event handlers
Worker methods
Next topic: Traversal API
Previous topic: Thread API