I am trying to make this code return each employees name.
var company = {
employees: [
{
name: "doug"
},
{
name: "AJ"
}
],
getName: function(employee){
return employee.name
},
getNames: function(){
return this.employees.map(this.getName)
},
delayedGetNames: function(){
setTimeout(this.getNames,500)
}
}
console.log(company.delayedGetNames());
However, when I run the code I get "TypeError: Cannot read property 'map' of undefined"
I have tried doing
setTimeout(this.getNames.bind(this),500)
I just get undefined returned to me.
Can anyone help me out?