Reputation: 63
I've been trying to get multiple functions working in 1 const
, but it either does not work (Uncaught SyntaxError: Unexpected identifier
) or I'm missing something, and I hope someone can help.
Why does this work:
const dynamicresponse = {
login(response) {
alert(response);
}
}
And why does this not work?
const dynamicresponse = {
login(response) {
alert(response);
}
adminsearchuser(response) {
alert(response);
}
}
And is there a way to get the example above working?
Upvotes: 0
Views: 56
Reputation: 56744
You're missing a comma after the body of your login()
method.
const dynamicresponse = {
login(response) {
alert(response);
},
adminsearchuser(response) {
alert(response);
}
}
dynamicresponse.login('foo')
dynamicresponse.adminsearchuser('foo')
The notation you tried is used on Javascript class
objects.
Upvotes: 3