The assumption is that you've got a block of code that looks like this
function buildbuttons() {
var some_id;
for( some_id in somelist ) {
var button = document.createElement("button");
button.onclick = function() {
send_message_to( some_id );
}
some_panel.appendChild(button);
}
}
All the button onclick methods share the same some_id variable, which will be the last value assigned to some_id.
immediately-invoked-function-expressions are how you capture the current value (at the time of the loop iteration) of some_id in the closure so each button references the value you expect it to.