我是使用下划线/节点的 n00b 并且正在尝试理解链接函数的概念。但是,当尝试在节点中链接函数时,我无法得出正确的输出。从下划线的链接部分获取示例片段会产生“无效的 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 不会产生错误。你们中的一个可以帮我找出错误吗?
谢谢!