I have a function which binds different form inputs
function bindInputs() {
$(".inputContainer").each(function(i){
var inputContainer = $(this),
input = $("input.input", inputContainer),
inputType = inputContainer.attr("data-inputType"),
input_Id = inputContainer.attr("id").replace("inputContainer_", "");
if(inputType == "TextEditor") {
input.unbind("change").bind("change", function() {
inputContainer.removeClass("nullValue");
var value = input.val();
saveInputValue(input_Id, value);
});
return true;
}
if(inputType == "NumericEditor") {
input.numeric({ allow: "." });
input.unbind("change").bind("change", function() {
inputContainer.removeClass("nullValue");
var value = getNumericValue(input.val());
saveInputValue(input_Id, value);
});
}
// so on
});
};
Is this function creating memory leaks? The thing i am worried about is that i keep all the shared variables on top and use them inside "change" callback functions.
Would make a difference if i re-calculate the shared variables on the callback functions?
if(inputType == "TextEditor") {
input.unbind("change").bind("change", function() {
var elem = $(this),
inputContainer = elem.closest(".inputContainer"),
input_Id = inputContainer.attr("id").replace("inputContainer_", "");
inputContainer.removeClass("nullValue");
var value = input.val();
saveInputValue(input_Id, value);
});
return true;
}
input = $("input.input", inputContainer")). For start, please post valid code.