简体   繁体   中英

TypeError: (fn) is not iterable when just executing a function

So I have a very simple code:

// doesn't matter, just be sure that we have an array
const tasks = Array.isArray(result) ? [...result] : [result];

// works
for (let i = 0; i < tasks.length; i++) {
    this.executeNativeCommand(tasks[i].command, ...tasks[i].args);
}

// TypeError: this.executeNativeCommand is not iterable (cannot read property Symbol(Symbol.iterator))
tasks.forEach(task => {
    this.executeNativeCommand(task.command, ...task.args);
});

Also tried this['executeNativeCommand'] — it worked. What sort of magic is it?

The message is wrong and confusing, it should be tasks[i].args is not iterable / task.args is not iterable .

You probably ran into this V8 bug .

It was fixed three months ago (February 2020), but it seems it hasn't landed in stable node.js or Chrome yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM