title: ExtJs 4 callbacks
body: <p>I had a hard time trying to find out why my assignments where lost, and found that callbacks scope was different than I thought.</p>
  
  <p>What I did was to create a variable in a controller, then trying to pass a callback to a window created by the controller, then, on an event on that window, call-back a function in the controller.</p>
  
  <p>For example, in my controller I have:</p>
  
  <pre><code>callWindow: function(){
    var myWin = Ext.Create('MyApp.view.myWin', {doSomething: this.doSomething});
  },
  
  doSomething: function(data){
    this.myData = data;
  },
  
  useTheData: function(){
    console.log(this.myData);
  }
  </code></pre>
  
  <p>In myWin's controller, I have an even handler that calls doSomething this way:</p>
  
  <pre><code>onBtnClick: function(button){
    var win = button.up('window');
    var data = {id: 1, name: "John"}; // please, don't pay attention to this, it's a record I'm passing to the caller.
    win.doSomething(data);
  }
  </code></pre>
  
  <p>As you can see, in "doSomething" function, I'm assigning the controller var myData, with the value passed by the window's controller. Initially I thought the scope of "doSomething" was the caller controller, but it's the window's controller, that's why useTheData gives an error saying this.myData is null.</p>
  
  <p>I've solved the problem by passing a new parameter named "caller: this", and in doSomething, receiving that parameter, and using it instead of "this".</p>
  
  <p>The question is, is there a easy (with less steps) way to do this?.</p>