jQuery $ .when().then()和.done()之间的区别

编程入门 行业动态 更新时间:2024-10-27 10:25:39
本文介绍了jQuery $ .when().then()和.done()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图了解两者之间的区别

I am trying to understand the difference between

$.when(...).then(...) $.when(...).done(...)

在jQuery中.据我了解,当内部对象完成加载时,它们都将执行.但是有什么区别.实例将不胜感激.

in jQuery. As far as I understood both of them executes when objects inside when are finished loading. But what is the difference. Examples will be really appreciated.

推荐答案

.done()仅具有成功回调.

.then()同时具有成功和失败回调.

.then() has both success and fail callbacks.

从jQuery 1.8开始,deferred.then()方法返回一个新的Promise 可以过滤通过 函数,替换现在不推荐使用的deferred.pipe()方法.

As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method.

deferred.done()方法接受一个或多个参数,所有这些参数 可以是单个函数或函数数组.

The deferred.done() method accepts one or more arguments, all of which can be either a single function or an array of functions.

由于deferred.done()返回延迟的对象,因此其他方法 可以将延迟的对象链接到此对象,包括其他对象 .done()方法.解决延迟问题后,将完成doneCallbacks 使用提供给resolve或resolveWith的参数执行 方法按照添加顺序进行调用.

Since deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one, including additional .done() methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the resolve or resolveWith method call in the order they were added.

更多推荐

jQuery $ .when().then()和.done()之间的区别

本文发布于:2023-11-23 19:29:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!