Thuộc tính writeable.w preferObjectMode được sử dụng để lấy thuộc tính objectMode của Luồng có thể ghi đã cho. Thuộc tính sẽ trả về 'true' nếu chế độ đối tượng được đặt, các thuộc tính khác sẽ trả về 'false'.
Cú pháp
writeable.writableObjectMode
Ví dụ
Tạo một tệp có tên - writeableObjectMode.js và sao chép đoạn mã dưới đây. Sau khi tạo tệp, sử dụng lệnh sau để chạy mã này như được hiển thị trong ví dụ bên dưới -
Nútnode writableObjectMode.js
writeableObjectMode.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); Đầu ra
C:\home\node>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING true
Ví dụ
Hãy xem thêm một ví dụ.
// 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); Đầu ra
C:\home\node>> node writableObjectMode.js Welcome to TutorialsPoint ! SIMPLY LEARNING undefined Default value is undefined.