tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

JS Lesson 4: getGithubInfo should not return the xmlhttp object

Open codebru opened this issue 5 years ago • 0 comments

Where

The tutorial https://github.com/codebar/tutorials/blob/gh-pages/js/lesson4/tutorial.md

What

The code block

function getGithubInfo(username) {
  var url = 'https://api.github.com/users/' + username;

  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open('GET', url, false);
  xmlhttp.send();

  return xmlhttp;
}

returns the xmlhttp object. I would argue that this is bad practice and the function should return only the data or a signifier of failure, for example throwing an error. The reason I think this is bad practice is that it as a function should only give data, and should not let its functionality "leak out" (sorry I am struggling to describe this well).

Am I willing to fix

Yes, I just wanted to know if people agreed with me first :)

codebru avatar Nov 20 '19 19:11 codebru