I have an object with some properties such as;
JavaScript
x
8
1
integrationConfig = {
2
iconEmoji: ':myIconEmoji:',
3
team: 'myTeam',
4
text: 'myText',
5
channel: 'myChannel',
6
botName: 'myBot'
7
}
8
I am passing this object to a function below as shown (attachments
is not important).
JavaScript
1
2
1
return await this.pushToSlack(integrationConfig, attachments);
2
Importantly, this function is part of an NPM Package, so I don’t want to change the function declaration.
The function is declared like this:
JavaScript
1
4
1
exports.pushToSlack = function (channel, text, botName, iconEmoji, team, attachments, cb = function () {}) {
2
// […]
3
}
4
I put some breakpoint to the pushToSlack
function but the debugger didn’t jump into that line. I guess the function is not called somehow. I also receive this error:
JavaScript
1
4
1
Debug: internal, implementation, error
2
TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
3
at Function.all (<anonymous>)
4
Have you got any idea?
Advertisement
Answer
Spread syntax is not usable for that
use Destructuring assignment
JavaScript
1
8
1
integrationConfig =
2
{ iconEmoji : ':myIconEmoji:'
3
, team : 'myTeam'
4
, text : 'myText'
5
, channel : 'myChannel'
6
, botName : 'myBot'
7
}
8
the call :
JavaScript
1
2
1
return await this.pushToSlack( integrationConfig, attachments);
2
the function :
JavaScript
1
5
1
exports.pushToSlack = function ({channel, text, botName, iconEmoji, team}, attachments,
2
//..Destructuring assignment....^.......................................^
3
// Arguments can be in any order you want
4
// and no obligation to have all of them
5