3

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 (= {}).

Community
  • 1
  • 1
Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138

1 Answers1

4

This is a destructuring related bug that was fixed in Node 6.9.2

Notable Changes

  • deps:
    • V8: Various fixes to destructuring edge cases
      • cherry-pick 3c39bac from V8 upstream (Cristian Cavalli) #9138
      • cherry pick 7166503 from upstream v8 (Cristian Cavalli) #9173
Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138