Pass a callback that updates response state.

Callback Dispatch

callback_dispatch.js
const mode = "status";
let access = "";
let response = "";

function dispatch(command, callback) {
  const normalized = command.trim().toLowerCase();
  callback(normalized);
}

dispatch(mode, (command) => {
  if (command === "archive") {
    access = "review";
  } else {
    access = "ok";
  }
  response = "handled:" + command;
});

console.log("mode=" + mode);
console.log("access=" + access);
console.log(response);
callback-dispatch A callback lets dispatch code hand a normalized value to another function. The replay shows the callback body as the dispatched work.