0

I have got this code which register a callback method.

function BaseClass() {
var context = this;
(function initialize() {
      context.registerField(context.Name, function updateValues(Name, value) {
                    context.Value = value;
                });
            })();
}

This is how the callback methods are being called.

updateValues.call(null, names, values);

The issue is the registerfield() is called multiple times with different context.

When the call back are being called they are not getting executed on correct context. How can I invoke the callback on correct objects? updateValues.call(null, names, values);

subs
  • 2,189
  • 12
  • 35
  • 59
  • I suspect invoking with null is the culprit here but I am not sure how to solve this. – subs Feb 10 '17 at 10:33
  • "The issue is the registerfield() is called multiple times with different context" — You are only calling it once. It seems your [mcve] is not complete. – Quentin Feb 10 '17 at 10:36
  • I'm guessing this is probably a duplicate of [this question](http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example) – Quentin Feb 10 '17 at 10:36

0 Answers0