0

I don't so much want a solution to what I am doing wrong as much as I want an explanation of what I am doing so far. This is mostly the starter-code given to me by an instructor. The purpose was to get my repositories from GitHub and display them on the page. I don't completely understand the code. Any help would be appreciated. Thank you. Any help on why my array repos.all is empty would be welcome too.

 (function(module) {
      const repos = {};
      function MyRepos(rawDataObj) {
        Object.keys(rawDataObj).forEach(key =>[key] = rawDataObj[key]);
    }
    console.log(rawDataObj);
    repos.all = [];
    console.log(repos.all);
    repos.requestRepos = function(callback){
      $.get(`https://api.github.com/users/userName/repos?access_token=${token}`)
      .then(
        reults => {
          console.log(results);
          repos.all = reults.map(ele => new MyRepos(ele));
          callback();
        });
    };
    repos.with = attr => repos.all.filter(repo => repo[attr]);
    module.repos = repos;
    })(window);
Potluck
  • 35
  • 5
  • 1
    I think you should ask your instructor, he'll be able to help you best. – Bergi May 15 '17 at 05:12
  • If you don't understand it completely, what parts *do* you understand? And which parts not? Please ask a specific question. – Bergi May 15 '17 at 05:12
  • On break from class for a bit, mostly trying to understand APIs before I get back x.x – Potluck May 15 '17 at 05:13
  • I do not understand what .map or repos.all.filter is doing at the end. – Potluck May 15 '17 at 05:14
  • "*why my array repos.all is empty*" - probably a variant of [Why is my variable unaltered after I modify it inside of a function?](http://stackoverflow.com/q/23667086/1048572) - you call `with` too early - but you haven't shown us how you call the code and at what point you expected it to be filled. – Bergi May 15 '17 at 05:15
  • nor completely what the word 'key' is referring to. – Potluck May 15 '17 at 05:15
  • Do I need to call function wrapped in an iffe? Isn't that somewhat like document.ready? – Potluck May 15 '17 at 05:17
  • You need to call it from within the `callback` that is passed to `requestRepos` - otherwise the array isn't populated yet. Regarding `key`, it looks a lot like there's a `this` missing in front of `[key] = …`. – Bergi May 15 '17 at 05:20
  • Thank you for your help. I figured it out. – Potluck May 15 '17 at 05:28

0 Answers0