Skip to content

JS Lesson 4: getGithubInfo should not return the xmlhttp object #451

Open
@codebru

Description

@codebru

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions