.resolve()和.promise()有什么区别? [英] What is the difference between .resolve() and .promise()?

查看:442
本文介绍了.resolve()和.promise()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究jQuery的延迟功能.我已经在互联网上尝试了几个示例.我了解它的概念,但不了解resolve()promise()之间的区别.

I'm digging into jQuery's deferred features. I've tried several examples on the internet. I understood its concept, but I don't understand the difference between resolve() and promise().

resolve()promise()有什么区别?

推荐答案

resolve()promise()都是jQuery Deferred对象上的方法.

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

首先是jQuery 有关Deferred的文档的片段:

First a snippet from the jQuery documentation about Deferred:

了解Deferred的一种模式是将其视为 链感知功能包装器. deferred.then(),deferred.done(), 和deferred.fail()方法指定要调用的函数,并且 deferred.resolve(args)或deferred.reject(args)方法调用" 可以使用您提供的参数来实现功能.

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().

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().

在有关promise()的博客文章m-sharp中:

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

当您要向调用API提供一些要 订阅,但不能解决或拒绝延期.

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.

这篇关于.resolve()和.promise()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆