我正在深入jQuery的延迟功能。我在互联网上试过几个例子。我理解它的概念,但我不明白resolve()和promise()之间的区别。
resolve()和promise()之间有什么区别?
解决方法
resolve()和promise()都是jQuery Deferred对象上的方法。
首先是来自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.
考虑到这一点,promise()返回一个非常类似于Deferred对象的对象,除了它只有then(),done()和fail()方法,没有resolve()或reject()。
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.