function context/scope issue

function context/scope issue

In my widget I have an instance of UI dialog with button OK which  triggers "onOk" event in my widget.
Before triggering my event I set  a flag   "inProgess" to prevent multiple callbacks.
And there lies my problem.
When i try to call "succededFunction" argument in function attached to onOk event:



  1.  function InfoOk(ev, args) {
  2.               args.succededFunction();
  3.               //setTimeout(args.succededFunction, 1);
  4.           }

It provides (a copy of?) my widget in context but without attached flag and original 
widget keeps the flag on and prevents repeated ok callbacks which is the purpose of my widget.
The funny thing is if "succededFunction" is called in setTimeout function it works like expected(shuts down the flag).

Anyone has a clue?






  1.        _create: function () {
  2.                   $.myCompany.controlBase.prototype._create.apply(this, arguments);
  3.                   var self = this;
  4.                   this.dialog = $("#dialog").dialog({
  5.                       autoOpen: false,
  6.                       buttons: {
  7.                           "Ok": function (ev, args) {
  8.                               if (!self.inProgress)
  9.                                   self.inProgress = !(false === self._trigger("onOk", null, {
  10.                                       dialog: self.dialog,
  11.                                       succededFunction: function () {
  12.                                           self.inProgress = false;
  13.                                           self._trigger('onDialogSucceded', null, { dialog: self.dialog });
  14.                                           self.dialog.dialog('close');
  15.                                       },
  16.                                       failFunction: function (err) {
  17.                                           self.inProgress = false;
  18.                                           $.myCompany.controlBase.prototype._onError.apply(self, arguments);
  19.                                       },
  20.                                       item: self.item
  21.                                   }));
  22.                           },
  23.                           "Cancel": function () { $(this).dialog("close"); }
  24.                       },
  25.                       title: self.options.title
  26.                   });
  27.               },