有没有办法在ie9+中实现promise [英] is there a way to implement promises in ie9+

查看:32
本文介绍了有没有办法在ie9+中实现promise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 IE9+ 上实现 native promise,但 Internet Explorer 似乎无法识别Promise"类/对象.我在 http://caniuse.com/#search=Promise 中搜索,看到 IE 不没有 Promise 对象.但这很奇怪,因为 jQueryAngular 与 promise 一起工作,并且在 IE9+ 中工作.也许他们正在实施他们自己的承诺?? **我可以实现我自己的承诺吗?**

I m trying to implement native promise on IE9+ and it seems that internet explorer does not Recognize the "Promise" class/object. I searched in http://caniuse.com/#search=Promise and saw that IE don't have Promise object. But this is strange because jQuery and Angular works with promises and working in IE9+. Maybe they are implementing their own Promise?? ** Can i implement my own promise ?**

推荐答案

什么是原生"

原生意味着它写在浏览器的代码基础中,而不是写在用户级代码中.为了在 IE9 中本地实现 promise,您必须从 Microsoft 获得一份 IE9 源代码的副本,编写代码,编译并分发它.虽然这是可行的,但这不是一个非常可行的选择.

What's "native"

Being native means that it is written inside the browser's code base and not in user-level code. In order to implement promises natively in IE9 you'd have to obtain a copy of the IE9 source code from Microsoft, code those in, compile and distribute it. While that's doable that's not a very viable option.

另一方面 - userlevel 中有几个 promise 库.完全可以实现您自己的承诺实现 - 这里是关于如何做的很棒的博文.

On the other hand - there are several promise libraries that exist in userlevel. It's perfectly possible to implement your own promise implementation - here is a great blog post on how.

您可以自由包含一个库,例如 (bluebird) 或 Q 实现此 API,并将在未来继续与 ES6 承诺良好配合.值得一提的是,例如 Bluebird 在 IE6+ 上运行,因此您的情况应该没有问题.

You can freely include a library like bluebird (bluebird) or Q that fulfill this API and will continue working well with ES6 promises in the future. It is worth mentioning that Bluebird for instance runs on IE6+ so there should be no issues in your case.

例如这里是Angular的实现这是 jQuery 的实现 - 在我看来,Angular 的可读性更强.

For example here is Angular's implementation and here is jQuery's implementation - Angular's is more readable in my opinion.

另请注意,与上面留下的评论相反,Promises/A+ 规范对 Promises/A+ 规范进行了标准化,其中 Angular 之类的库符合,而 jQuery 之类的库正在努力符合并且可能会在下一个版本中.本机承诺也符合标准并对其进行超集.

Also note that contrary to the coment left above promises are standardized by the Promises/A+ specification with libraries like Angular conform to and libraries like jQuery are working on conforming to and likely will in the next version. Native promises also conform to the standard and superset it.

这篇关于有没有办法在ie9+中实现promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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