私はアンダースコア/ノードの使用に不慣れで、連鎖関数の概念を理解しようとしています。ただし、ノードで関数をチェーンしようとすると、適切な出力を引き出すことができません。アンダースコアの連鎖セクションからスニップの例を取得すると、「無効な REPL キーワード」が生成されます。
var __ = require("underscore"); //for underscore use in node
var lyrics = [
{line: 1, words: "I'm a lumberjack and I'm okay"},
{line: 2, words: "I sleep all night and I work all day"},
{line: 3, words: "He's a lumberjack and he's okay"},
{line: 4, words: "He sleeps all night and he works all day"}
];
__.chain(lyrics) //in the console chain appears to run and return correctly, but then
.map(function(line) { return line.words.split(' '); }) //Invalid REPL keyword
.flatten() //Invalid REPL keyword
.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {}) //Invalid REPL keyword
.value(); //Invalid REPL keyword
この場合、私はASIの被害者ですか? その場合、「;」はどこにありますか 挿入しようとしていますか?このスニペットを JSHint にプラグインしてもエラーが発生しないため、混乱しています。エラーを特定するのを手伝ってもらえますか?
ありがとう!