Monday, 24 April 2017

Why is this spread operator crashing the runtime?

There's got to be a better way to ask this, but I'm just not sure the exact cause.

Here's the code snippet first, I'll deconstruct it in a moment.

this.argArr = [['arg1', 'arg2'], ['foo', 'bar'], ['you get ', 'the point']];

this.evalArgsFromArr = function () {
  var out = [];
  for (var _ = 0; _ < parent.argArr.length; _++) {
    out.push(someFunction(...parent.argArr[_])); // This likes to crash?
  }
  return out;
};

This function is part of an object, of course.

The idea is that, each item in parent.argArr should be an array, containing two arguments for someFunction(), which also handily serve as a human-readable condensation of the output. My understanding is, used on an iterable object (such as the arrays stored in parent.argArr), the spread operator outputs each individual value separately. (For example, the first run of the for loop should output someFunction('arg1', 'arg2').)

Whenever I run a file containing this in Node.js or PHP, the runtime almost immediately crashes, despite it not yet being called, citing the spread operator [...] as unexpected.

Here's the error message, if it helps: Error Message



via Papayaman1000

No comments:

Post a Comment