Please explain a jQuery promise

This comes from here:

I am not sure what key words are defined by jQuery versus what is needed in this implementation...

var maybePromise = Math.random() > 0.5 ? 10 : Promise.resolve(10);
var definitelyPromise = Promise.resolve(maybePromise);
// equivalent to
var definitelyPromise = new Promise(function (fulfill, reject) {
  if (isPromise(maybePromise)) {
    maybePromise.then(fulfill, reject);
  } else {
newbiewebSr. Software EngineerAsked:
Who is Participating?
Julian HansenConnect With a Mentor Commented:
None of the code is jQuery specific - it is all plain JavaScript

The example was about how to convert something that may or may not be a promise into a genuine promise so you can perform all the promisy things on it.
newbiewebSr. Software EngineerAuthor Commented:
So, Promise in an object defined in the javascript library?

Anything that starts with Promise. is a method also defined in the  javascript library?

What about isPromise() ?

Julian HansenConnect With a Mentor Commented:
That document describes Promises but the code is not strictly native JavaScript. The functions isPromise and fulfill are not methods on the promise - I imagine they are implied functions that would perform the operations of determining if an object is a Promise (has a .then() method for example) and fulfill (resolving the promise).

You can read more about the JavaScript promise here
newbiewebSr. Software EngineerAuthor Commented:
Julian HansenCommented:
You are welcome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.