javascript - Best approach to assigning constructors objects in array -


i receiving server array of objects:

[{name: 'al'}, {name: 'ann'}] 

i'd convert these person constructor created. right doing this:

  function person(attributes) {     angular.extend(this, attributes);     return this;   }    person.prototype.getname = function() {     return "my name " + this.name;   }    $scope.people = [];    $http.get('people')   .success(function(people) {     $scope.people = people.map(function(person, i) {       return new person(person);     });   }); 

can think of better approach? 1 not require having convert each of objects inside array desired constructor? perhaps way tell array objects within instances of person @ times. or maybe can include getname method $scope.people array , somehow have objects within call method located in parent array...

also if there way can convert object constructor (along prototype methods) without using angular.extend did in example nice. thanks.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -