title: JS - object adds self to array when created
body: <p>I am trying to have an object in js add itself to a list as it is being created. I thought simply adding <code>this</code> as the parameter would have worked, but it seems to not work for some reason. How should I do this?
      </p></p>
  
  <pre><code>&lt;script&gt;
  function car(make, model, year, color, owner) {
      this.make = make;
      this.model = model;
      this.year = year;
      this.color = color;
      this.owner = owner || null;
      this.to_string = function() {
          return 
              "Car: " + this.color + " " + this.year + " " + this.make + " " + this.model + "\n" +
              "Owner: " + this.owner.name;
      }
      all_cars.add(this); //&lt;---issue
      owner.buy_car(this); //&lt;---issue
  }
  
  var all_cars = function() {
      this.list = new Array();
      this.add = function(car) {
          this.list.push(car);
      }
      this.to_string = function() {
          var r = "";
          for (var i = 0; i &lt; this.list.length; i++) {
              r += ((r == "") ? "" : "\n\n");
              r += this.list[i].to_string();
          }
          return "ALL CARS\n" + r;
      }
  }
  
  function human(name, cars) {
  this.name = name;
      this.cars = cars || new Array();
      this.buy_car = function(car) {
          car.owner = this.name;
          this.array.push(car);
      }
      this.sell_car = function(index, buyer) {
          buyer.buy_car(this.cars.splice(index));
      }
  }
  
  var vin_254s45s8wf6a = new car("Honda", "Accord", 2007, "WHT");
  var vin_45d8s3g3j8x8 = new car("Toyota", "Camery", 2009, "BLU");
  var vin_9s3d4f8s5w9d = new car("BMW", "JX5", 2017, "SLV");
  var vin_45s6a8d5s9g2 = new car("Lexus", "CT 200h Hybrid F SPORT", 2016, "RED");
  var vin_9s3d45s8wf6a = new car("Toyota", "Navta", 2001, "GRN");
  var mike = new Human("Mike Smith", [vin_45s6a8d5s9g2, vin_45d8s3g3j8x8]);
  var jim = new Human("Jim Hamelton", [vin_9s3d4f8s5w9d]);
  var evie = new Human("Evelyn Ma", [vin_9s3d45s8wf6a]);
  
  document.getElementById("demo").innerHTML = "HI"; //all_cars.to_string()
  &lt;/script&gt;
  </code></pre>