Arbejdsglæde
Arbejdsglæde

Reputation: 14088

JavaScript and knockoutjs strange behavior for this keyword

I have 3 partial knockoutjs binding in my pape

var model1= function()
        {
            self = this;
//somemethods here..
}
 var model2= function()
        {
            self = this;
 self.status = null;
            self.id = ko.observable(1);
             self.processingStatus = function ()
            {
                self.status = setInterval(function(){
                    var id = self.userId();//**self conteine link to model3**                                                                        
                }, 1100);
              }
            //somemethods here..

}

 var model3= function()
        {
            self = this;
//somemethods here..
}

  var m1 = new model1();                
ko.applyBindings(m1, document.getElementById("id1"));

        var m2 = new model2();
        ko.applyBindings(m2, document.getElementById("id2"));

        var m3= new modelHistory();
        ko.applyBindings(m3, document.getElementById("id3"));

inside of processingStatus method in model2, self pointer continent model3 data. What does it happens and how to have different self pointer in each model class ?

Upvotes: 1

Views: 42

Answers (1)

Romain B.
Romain B.

Reputation: 266

You forgot the 'var' for self variables.

var self = this;

Upvotes: 1

Related Questions