title: javascript passing a function in a class that needs another function from that class object
body: <p>I am passing a function in a class or var object as an argument to another function.
  The function that takes in the function from the class executes that function. 
  It would work fine, however the function of the class calls another function from the class. 
  The console outputs the error that the function being called in the class function is undefined.</p>
  
  <p>The following might illustrate a bit better</p>
  
  <pre><code>//the class variable in someClass.js
  function(params...){
    getSomethingInClass: function(){
       // return some variable
    }
  
    functionThatIsPassed: function(arg){
      var theCalledFunction = getSomethingInClass();
      //do something with theCalledFunction
    }
  }
  
  //SOME WHERE ELSE in another function in another file
  OtherFunction: function(){
  //someClass is a variable being used here
    FunctionThatTakesFunction(this.someClassVar.functionThatIsPassed);
  }
  
  
  //FunctionThatTakesFunction is implemented in another file
  FunctionThatTakesFunction(callbackFun){
    callbackFun(someArg);
  }
  </code></pre>
  
  <p>The above will work if I change it to pass the entire object someClass object. That is bad programming practice to pass the object because FunctionThatTakesFunction needs to know the functions of its argument
  For example</p>
  
  <pre><code>//THIS WORKS!
  //other stuff is same 
  
  //SOME WHERE ELSE in another function in another file
  OtherFunction: function(){
  //someClass is a variable being used here
    FunctionThatTakesFunction(this.someClassVar);
  }
  
  
  //FunctionThatTakesFunction is implemented in another file
  FunctionThatTakesFunction(object){
    object.functionThatIsPassed(someArg);
  }
  </code></pre>