如何将jQuery Deferred对象转换为ES6 Promise [英] How to convert a jQuery Deferred object to an ES6 Promise
本文介绍了如何将jQuery Deferred对象转换为ES6 Promise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是转换jQuery Deferred
的正确方法吗?到 承诺
?
Is this the correct way to convert jQuery Deferred
to a Promise
?
var p = Promise.resolve($.getJSON('api/values', null));
还有其他方法吗?
有什么限制?我已经读过某个地方,jQuery延迟不支持异常,所以我假设从延迟创建的承诺都不会。它是否正确?
What are the limitations? I've read somewhere that jQuery deferred does not support exceptions, so I assume that a promise created out of a deferred would neither. Is this correct?
推荐答案
是的,Promise.resolve()API支持thenable作为参数。所以传递一个jquery defer对象就可以了。
Yes it should, the Promise.resolve() API supports thenable as argument. So passing a jquery defer object would work just fine.
这篇关于如何将jQuery Deferred对象转换为ES6 Promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文