I have a question, perhaps a very simple one, but whatever. When you register an event listener inside an asynchronous function, I believe that all values โโinside this function will be non-existent when the function runs it.
However, the event listener, as shown in the code below, can still access the values variable, how can I do this? Is the variable stored inside the event listener somehow?
$.ajax({ type: "GET", cache: false, url: "/whatever", success: function(data) { var values = ["Some Values", "Inside this Object"]; $("#id :checkbox").click(function() { var allValues = []; $('#id3 :checked').each(function() { allValues.push($(this).val()); }); $("#id2").val(allValues); callMe.init(values,allValues); }); } });
source share