I understand how to pass anonymous functions as a function parameter:
somefunction('value1',function(){alert('value2')});
But what I'm running into a problem with is if the function-as-a-parameter also has a variable inside it being used as a callback:
function FUNC(value1,callback) {
alert(value1);
callback();
}
function LOAD() {
// this function gets called when the page initially loads
var UN = document.getElementById('username');
FUNC('some value', function(){alert('user name: ' + UN.value)});
}
This produces a "ReferenceError: UN is not defined" error. I assume that is because the internals of FUNC() have no idea about the variable UN from LOAD(). How can I make this work? Use .bind, .call, .apply somewhere? I have found the following links, but are unsure if they are applicable.