0

Why this code not working?

I try save the array return of the function public "xy" in variables publics directly as in the function list() in php.

data = function() {
  this.xy = function() {
      return ['AAA', 'BBB'];
    }
    [this.x, this.y] = this.xy(); // Not Work
}

a = new data();
console.log(a.x)
output: 'error: TypeError: this.xy is not a function'
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
joserick
  • 327
  • 3
  • 11
  • 1
    You are missing a semi-colon after the function body. Since it's not there ASI rules don't fill it in and you execute `function() { return ['AAA', 'BBB']; } [this.x, this.y]` – VLAZ Oct 23 '19 at 19:02
  • 1
    `this.xy` is the result of creating a new function (which is an object), then reading the `this.y` (i.e. `undefined`) property from it, so it is `undefined`. Semi-colons matter in JS. – Quentin Oct 23 '19 at 19:02

0 Answers0