[英]Is there a property in javascript Object.type?
我現在正在研究Node.Js,遇到了這段代碼:
var combine = require('stream-combiner');
var through = require('through2');
var split = require('split');
var zlib = require('zlib');
module.exports = function () {
var grouper = through(write, end);
var current;
function write (line, _, next) {
if (line.length === 0) return next();
var row = JSON.parse(line);
if (row.type === 'genre') {
if (current) {
this.push(JSON.stringify(current) + '\n');
}
current = { name: row.name, books: [] };
}
else if (row.type === 'book') {
current.books.push(row.name);
}
next();
}
function end (next) {
if (current) {
this.push(JSON.stringify(current) + '\n');
}
next();
}
return combine(split(), grouper, zlib.createGzip());
};
write函數獲取的每一行都是一個json行,如下所示:
"name": "Neuromancer","genre": "cyberpunk"
預期結果是以下JSON對象:
{
"name": "cyberpunk",
"books": [
"Accelerando",
"Snow Crash",
"Neuromancer",
"The Diamond Age",
"Heavy Weather"
]}
等等。
基本上我的問題是-row.type是什么意思?
先感謝您! :D
您將類型參數放在var 行中
var row = JSON.parse(line);
因此,這不是對象函數的特殊屬性,僅是(位於var line的 )JSON中的一個參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.