我想在 Node.js (v0.4.11) 中使用 for each ... in
。
我是这样使用的:
var conf = {
index: {
path: {
first: "index.html",
pattern: "index/{num}.html"
},
template: "index.tpl",
limit: 8
},
feed: {
path: "feed.xml",
template: "atom.tpl",
limit: 8
}
}
for each (var index in conf) {
console.log(index.path);
}
我遇到了以下错误:
for each (var index in conf) {
^^^^
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected identifier
at Module._compile (module.js:397:25)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object.<anonymous> (/home/paul/dev/indexing/lib/Index.js:3:13)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
哪里出了错?for each ... in
自 Javascript 1.6 开始就被支持了。
请参考 MDN 获取有关 for each ... in
的用法信息。