0

This work fine:

var test = myFunc(2); // 4
function myFunc(id){
    return id*2
}

But this code doesn't work:

var test = myFunc(2); // {}
function myFunc(id) {
   return  myService.getById(id).then(function (result) {
       console.log(result[0].name); // John
       return result[0].name;
   });
}

Could you help me to fix my second example, please?

zlFast
  • 353
  • 1
  • 4
  • 9
  • 1
    You're defining a variable with the name `test` and a function with the name `test`. I have no idea what this is supposed to do. – Bergi Apr 04 '16 at 16:18
  • In your second snippet, your function returns a promise for the name "John". That's as good as it gets, because the name will only be available asynchronously. It does not need a fix. What is your problem with this, what do you considered broken? – Bergi Apr 04 '16 at 16:19

0 Answers0