Using underscore, I iterating a data, and adding in to a function, after i added, i am extending the function using 'prototype' - when i call that prototype i am not getting any value. and the prototype not available for public use at all..
here is my code :
var
data = {
people : [
{name:'Caring', state:'Tn', price:'100'},
{name:'Mo', state:'Ap', price:'200'},
{name:'af', state:'Jk', price:'33'},
{name:'adi', state:'Kl', price:'400'},
{name:'Hu', state:'Ka', price:'600'}
]
},
OrderItem = function(person){
this.person = person
getSummary = function(){
return person.name
+ ' spent '
+ person.price
+ ' in ' + person.state + '.';
}
return {getSummary : getSummary}
};
OrderItem.prototype.data = function(){
return this.person;
}
m = _.collect(data.people, function(value, key, list){
return new OrderItem(value);
})
_.each(m, function(value){
// console.log(value.getSummary()); //works fine
console.log(value.data()); //not working!
})
In the _.each method, when i call the value.data I am getting error. how to fix this?