I have an associative array of objects that I want to extend with a number of functions.
myCtrls //Array of objects
I do this with the following loop
$(document).ready(function() { for (ctrlName in fieldCtrls){ var ctrl = fieldCtrls[ctrlName]; ctrl.Initialize = function(){ //Do some stuff ctrl.someProperty = "newValue"; } ctrl.Validate= function(){ //Do some more stuff ctrl.someProperty = "validation ok"; } }
Later on, I execute a function like this. However the variable 'ctrl' now always points to the last object in 'fieldCtrls'. How can I make the variable 'ctrl' work inside 'initialize()' and 'Validate()'?
fieldCtrls['id'].Validate();