worker.workerData
添加於:v10.5.0
一個任意 JavaScript 值,其中包含傳遞給此線程的 Worker
構造函數的數據的克隆。
根據 HTML structured clone algorithm ,就像使用
一樣克隆數據。postMessage()
const { Worker, isMainThread, workerData } = require('node:worker_threads');
if (isMainThread) {
const worker = new Worker(__filename, { workerData: 'Hello, world!' });
} else {
console.log(workerData); // Prints 'Hello, world!'.
}
相關用法
- Node.js worker.receiveMessageOnPort(port)用法及代碼示例
- Node.js worker.markAsUntransferable(object)用法及代碼示例
- Node.js worker.SHARE_ENV用法及代碼示例
- Node.js worker.isMainThread用法及代碼示例
- Node.js worker.parentPort用法及代碼示例
- Node.js worker.getEnvironmentData(key)用法及代碼示例
- Node.js writeStream.getColorDepth()用法及代碼示例
- Node.js writeStream.cursorTo()用法及代碼示例
- Node.js writable._construct(callback)用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Node.js writeStream.moveCursor()用法及代碼示例
- Node.js writeStream.getWindowSize()用法及代碼示例
- Node.js writeStream.columns用法及代碼示例
- Node.js writeStream.clearScreenDown()用法及代碼示例
- Node.js writeStream.isTTY用法及代碼示例
- Node.js writeStream.hasColors()用法及代碼示例
- Node.js writeStream.rows用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 worker.workerData。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。