jquery – .resolve()和.promise()之间有什么区别?

前端之家收集整理的这篇文章主要介绍了jquery – .resolve()和.promise()之间有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在深入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()。

博客文章m-sharp引用了关于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.

原文链接:https://www.f2er.com/jquery/184306.html

猜你在找的jQuery相关文章