[Solved] accessing methods outside the constructor using javascript?


The this is referring to the Car, not the Garage. Try assigning the outer this to a variable:

var Garage = function(location){
    this.someRandomMethod = function(){
      alert("I am a method");
    }

    var garage = this;

    // car object
    var Car = function(make,model){
      this.model = model;
      this.make  = make;

      var accessRandom = function(){
         garage.someRandomMethod();
       }
    }
}

1

solved accessing methods outside the constructor using javascript?