0

I'm having trouble understanding why my values that I've retrieve from the API, is not being stored in this.schedule. When I console.log my result from my call, I see the returned Promise. My assumption is that when I use .then, I am storing the value into the variable schedule. What am I overlooking?

var getData = function(url, teamId) {
  var object = {
    "schedule": [],
    "record": null,
    "nextSixGames": [],
    "url": url
  };

  this.url = url
  var schedule = utils.teamSchedule(url, teamId).then(function(result) {
    return result
  });

  this.schedule = schedule;

  return object;
}

getData(URL, teamID)
console.log(getData(URL, teamID))
David Trinh
  • 319
  • 1
  • 12
  • You can't return from an asynchronous function. Promises are asynchronous. – Quentin Jan 13 '17 at 00:28
  • Also `this` is not what you think it is. `this.schedule` and `object.schedule` are two different properties – Patrick Evans Jan 13 '17 at 00:31
  • I'm still confused, I looked at other questions on stack overflow, but they all use console.logs to verify their answer. No where do they use "resolve()", I am guessing that is how I go about storing the values I want into a variable right? ` var schedule = utils.teamSchedule(url, teamId).then(function(result) { return Promise.resolve(result) });` I've tried resolving, but it doesn't seem to work, as it seems it is still async. Where am I going wrong. – David Trinh Jan 18 '17 at 19:54

0 Answers0