2014-02-26 48 views
1

奇怪的行爲,我有3個部分knockoutjs在我的帕普JavaScript和knockoutjs此關鍵字

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")); 

結合processingStatus方法MODEL2,指針大陸model3數據內。 它發生了什麼,以及如何在每個模型類中有不同的自指針?

回答

1

您忘記了自變量的'var'。

var self = this;