【发布时间】:2017-01-13 11:04:51
【问题描述】:
我有类似下面的代码:
class Foo {
foo() {
return this.query( { key : "value" }, {
multiple: true,
resolveForeignKeys: false
} );
}
query( conditions, {
cast = null,
multiple = false,
resolveForeignKeys = true
} = {} ) {
console.log( "working..." );
}
}
(new Foo()).foo();
当我在浏览器中运行此代码时,它运行良好。但是,当我通过 Node 运行它时,我会收到以下错误:
TypeError: Cannot read property 'multiple' of undefined.
当我从函数声明中删除默认值= {} 时,代码将运行良好。我也确信前几天这在另一台机器上运行良好。
我还发现了How to destructure option argument with all default values in ES6?,其中的答案表明问题出在缺少默认值(= {})。
【问题讨论】:
标签: javascript node.js