为什么不编译?
function (newDoc, oldDoc, userCtx) {
if (newDoc !== null) {
if (newDoc.type.toLowerCase() === 'test') {
let thisDoesNotWork = 5;
}
}
}
它抛出:
{
"error": "compilation_error",
"reason": "Expression does not eval to a function. (function (newDoc, oldDoc, userCtx) { if (newDoc !== null) { if (newDoc.type.toLowerCase() === 'test') { let thisDoesNotWork = 5; } } })"
}
[尝试通过向其添加新键来将其扩展到newDoc确实像以下一样也不起作用,并抛出相同的错误,但仅当您尝试使用它时才抛出该错误,而仅声明它则不然。
function (newDoc, oldDoc, userCtx) {
if (newDoc !== null) {
if (newDoc.type.toLowerCase() === 'test') {
let newDoc.thisDoesNotWork = 5;
}
}
}
您正在尝试对CouchDB JS引擎使用不受支持的语法。
您应该删除let变量声明并使用var
CouchDB依赖于支持ECMAScript Edition 5的SpiderMonkey 1.8.5