[英]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.