Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stupid(?) question #51

Closed
dctr opened this issue Apr 15, 2013 · 2 comments
Closed

Stupid(?) question #51

dctr opened this issue Apr 15, 2013 · 2 comments

Comments

@dctr
Copy link

dctr commented Apr 15, 2013

Hi everyone. I only do JS for a couple of weeks now and could not find out, why the code

  this.show = function(username, cb) {
    var command = username ? "/users/"+username : "/user";

    _request("GET", command, null, function(err, res) {
      cb(err, res);
    });
  };

Works with

  ....show('dctr', myFunc);

and with

  ....show(myFunc);

Why doesn't command evaluate to something absurd and cb fails but myFunc is called in both cases? At least i would have expected something like

  cb = username ? cb : username;

Thanks in advance for anwers...

@michael
Copy link
Collaborator

michael commented Apr 15, 2013

Actually this is a good question. This is not supposed to work when called with one param.

Something like this should do it:

this.show = function(username, cb) {
    var path = cb ? "/users/"+username : "/user";
    cb = cb ? cb : username;
    _request("GET", path, null, function(err, res) {
      cb(err, res);
    });
};

@dctr
Copy link
Author

dctr commented Apr 15, 2013

Strange thing, but as mentioned above, both work...

@dctr dctr closed this as completed Apr 15, 2013
punchagan pushed a commit to punchagan/github that referenced this issue Aug 23, 2014
Fix _.extend returning an array instead of an object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants