0

I have an object named promise and it has functions and string inside it. For printing the object i can use

console.log(promise);

but i have a string named "responseText" inside promise. If i try to print it using

console.log(promise.responseText);

,its showing as undefined. I can see the value of responseText by printing the object. But when i print using promise.responseText its showing undefined.

FYI

I am able to print all the functions inside promise, but I am not able to print the string. Please help.

9
  • responseText !== responsetext Commented Aug 24, 2017 at 12:11
  • I am printing it as console.log(obj.responseText); only. Editted the post. Commented Aug 24, 2017 at 12:14
  • Can you show how the object looks like? Commented Aug 24, 2017 at 12:14
  • Can you show your promise object Commented Aug 24, 2017 at 12:17
  • I suspect your promise is doing some async operation and is not completed at the time you did console.log. The classic async problem. Commented Aug 24, 2017 at 12:19

1 Answer 1

2

Use

var promise = {
  responseText: function(){
    return "responseText"
  }
}

console.log(promise.responseText())

OR

var promise = {
  responseText: function(){
    console.log("responseText")
  }
}

promise.responseText()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.