Hey! The problem is that you’re calling the function when you do refreshContactList() what you want instead is to pass the function itself:
addContact(entityId, refreshContactList);
Then inside addContact, you can choose when to run it:
function addContact(id, callback) {
// do something with id
if (typeof callback === "function") {
callback(); // only run it when needed
}
}
This makes it much more flexible, especially if you’re working in a team others can reuse addContact with different callbacks without changing its internals.