title: Pass class function as parameter to another class to use as callback in JavaScript
body: <p>Alright, so I have two classes.
  Class 1 contains a specific function, which accesses some of the class' properties. This is what it looks like:</p>
  
  <pre><code>function class1() {
      this.variable = "something";
  }
  
  class1.prototype.callback = function() {
      console.log(this.variable); // Returns undefined
  }
  </code></pre>
  
  <p>Class 2 can call any function it is given, and looks like this:</p>
  
  <pre><code>function class2() {}
  
  class2.prototype.caller = function(callback) {
      callback();
  }
  </code></pre>
  
  <p>Then in my regular Javascript I do this:</p>
  
  <pre><code>var c1 = new class1();
  var c2 = new class2();
  c2.caller(c1.callback);
  </code></pre>
  
  <p>It is supposed to return "something", however it throws an undefined error. I know it is because it is in the scope of class2 and it is trying to access the variable there, however I have no idea how to get it to execute within the scope of class1.</p>
  
  <p>Any help is greatly appreciated!</p>