What is the difference between .resolve() and .promise()? What is the difference between .resolve() and .promise()? jquery jquery

What is the difference between .resolve() and .promise()?


Both resolve() and promise() are methods on the jQuery Deferred object.

First a snippet from the jQuery documentation about Deferred:

One model for understanding Deferred is to think of it as a chain-aware function wrapper. The deferred.then(), deferred.done(), and deferred.fail() methods specify the functions to be called and the deferred.resolve(args) or deferred.reject(args) methods “call” the functions with the arguments you supply.

With that in mind, promise() returns an object that is very similar to the Deferred object except that it only has then(), done(), and fail() methods and does not have resolve() or reject().

From the blog post m-sharp referred to regarding promise():

This is useful when you want to give to the calling API something to subscribe to, but not the ability to resolve or reject the deferred.