I have code similar to the following:
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();
This code works fine when I run it in the browser. However, when I run it through Node, I will get the following error:
TypeError: Cannot read property 'multiple' of undefined.
When I remove the default value = {}
from the function declaration, the code will run fine. I'm also sure that this worked fine on another machine the other day.
I also found How to destructure option argument with all default values in ES6? where the answer suggests that the problem comes from a missing default value (= {}
).