คุณสมบัติ writable.writableObjectMode ใช้สำหรับรับคุณสมบัติ objectMode ของ Stream ที่เขียนได้ที่กำหนด พร็อพเพอร์ตี้จะคืนค่า 'จริง' หากมีการตั้งค่าโหมดอ็อบเจ็กต์ มิฉะนั้น จะส่งกลับ 'เท็จ'
ไวยากรณ์
writeable.writableObjectMode
ตัวอย่าง
สร้างไฟล์ที่มีชื่อ – เขียนได้ObjectMode.js และคัดลอกข้อมูลโค้ดด้านล่าง หลังจากสร้างไฟล์แล้ว ให้ใช้คำสั่งต่อไปนี้เพื่อเรียกใช้โค้ดนี้ดังแสดงในตัวอย่างด้านล่าง −
node writableObjectMode.js
เขียนได้ObjectMode.js
// Program to demonstrate writable.writableObjectMode property
// Importing the stream module
const stream = require('stream');
// Setting the objectMode to true
objectMode: true
// Creating a data stream with writable
const writable = new stream.Writable({
// Writing the data from stream
write: function(chunk, encoding, next) {
// Converting the data chunk to be displayed
console.log(chunk.toString());
next();
}
});
// Writing data - Not in the buffer queue
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
// Printing the length of the queue data
console.log(writable.writableObjectMode == true); ผลลัพธ์
C:\home\node>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING true
ตัวอย่าง
ลองดูอีกตัวอย่างหนึ่ง
// Program to demonstrate writable.writableObjectMode property
// Importing the stream module
const stream = require('stream');
// Creating a data stream with writable
const writable = new stream.Writable({
// Writing the data from stream
write: function(chunk, encoding, next) {
// Converting the data chunk to be displayed
console.log(chunk.toString());
next();
}
});
// Writing data - Not in the buffer queue
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
// Printing the length of the queue data
console.log(writable.writableObjectMode); ผลลัพธ์
C:\home\node>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING undefined Default value is undefined.