title: Casting plain objects to class instances in javascript
body: <pre><code>function Person() {
        var self = this;
  
        self.personName="";
        self.animals=[];
  }
  
  function Animal(){
       var self=this;
  
       self.animalName="";
       self.run=function(meters){
           .....
       }
  }
  </code></pre>
  
  <p>Server response:</p>
  
  <pre><code> [{personName:John,animals:[{animalName:cheetah},{animalName:giraffe}]} , {personName:Smith,animals:[{animalName:cat},{animalName:dog}]} ]
  </code></pre>
  
  <p>I'm getting Person array from server. I want to cast generic Person array to typed Person array. So I can use</p>
  
  <pre><code> persons[0].Animals[2].Run();
  </code></pre>
  
  <p>I founded Javascript's </p>
  
  <pre><code> Object.create(Person,person1);
  </code></pre>
  
  <p>But I want cross-browser version of it with array support</p>
  
  <pre><code>  ObjectArray.create(Person,persons);
  </code></pre>
  
  <p>or </p>
  
  <pre><code> Object.create(Person[],persons);
  </code></pre>