title: Cast var to custom class in Javascript
body: <p>I've got a custom class in Javascript called Booking:</p>
  
  <pre><code>function Booking(technicianID, startTime, start, street, zipcode, jobtypeID) {
      this.technicianID = technicianID;
      this.startTime = startTime;
      this.start = start;
      this.street = street;
      this.zipcode = zipcode;
      this.jobtypeID = jobtypeID;
  }
  </code></pre>
  
  <p>I want to use an object of this class as input in a function.</p>
  
  <pre><code>function bookTime(inputBooking) {
      var tmpBooking = inputBooking;
      alert("You chose: " + tmpBooking.start + ". Tech: " + tmpBooking.technicianID);
  }
  </code></pre>
  
  <p>But for some reason all I get from the alert is "undefined" for the variables. I guess it's because it doesn't see inputBooking as a Booking object, which means it doesn't have the variables start and technicianID...</p>
  
  <p>I read that there is a Object.create function you can use, but I can't get it to work.</p>
  
  <pre><code>    tmpBooking = Object.create(Booking, inputBooking); 
  </code></pre>
  
  <p>Any ideas on how to solve this? </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>If I send in the inputBooking object from javascript directly it works as expected. </p>
  
  <pre><code>    var tmpBooking = new Booking(tmpTechID, tmpStartTime, tmpStart, tmpStreet, tmpZipcode, tmpJobtypeID);
  
      bookTime(tmpBooking);
      //Works
  </code></pre>
  
  <p>But the problem is that I want to send a temp object to HTML and generate a button that will call the bookTime function:</p>
  
  <pre><code>    var tmpBooking = new Booking(tmpTechID, tmpStartTime, tmpStart, tmpStreet, tmpZipcode, tmpJobtypeID);
  
      resultsHTML += "&lt;a href=\"#\" onclick=\"bookTime('" + tmpBooking + "')\"&gt;Book!&lt;/a&gt;";
      //Doesn't work
  </code></pre>
  
  <p>When I run this with debugger it says that inputBooking is of type [object Object] and "Children could not be evaluated".. The result is that start and technicianID variables are undefined.</p>