1

为什么这不编译?

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;
    }
  }
}
4

1 回答 1

3

您正在尝试对 CouchDB JS 引擎使用不受支持的语法。

您应该删除let变量声明并使用var

CouchDB 依赖于支持 ECMAScript Edition 5 的 SpiderMonkey 1.8.5

于 2019-09-26T10:14:57.110 回答