简体   繁体   English

用于IE11的ES6代理Polyfill

[英]ES6 Proxy Polyfill for IE11

IE11 does not and will not implement ES2015 Proxy objects. IE11不会也不会实现ES2015代理对象。 Yet IE11's end of extended support is October 14, 2025. 然而,IE11的延长支持终止于2025年10月14日。

Is there any way to polyfill Proxy objects for IE11? 有没有办法为IE11 polyfill代理对象? All other browsers support Proxy already. 所有其他浏览器都支持Proxy。

If yes then we would all be able to use it in production today. 如果是,那么我们今天都可以在生产中使用它。 If not then we'll have to wait almost a decade... 如果没有,那么我们将不得不等待近十年......

Edit: I'm asking specifically for IE11 as I know IE to usually have IE specific features that I'm often not aware of. 编辑:我专门针对IE11,因为我知道IE通常具有我通常不知道的IE特定功能。

Edit2: I'm particularly interested in being able to implement a catch-all interceptor. Edit2:我特别感兴趣的是能够实现一个全能拦截器。 Similar to __getattr__ in Python. 类似于Python中的__getattr__ It only has to work in IE11. 它只需要在IE11中工作。

Best you can get is github: GoogleChrome/proxy-polyfill 你能得到的最好的是github:GoogleChrome / proxy-polyfill

According to Babel docs : 根据巴贝尔文档

Due to the limitations of ES5, Proxies cannot be transpiled or polyfilled. 由于ES5的限制,代理不能被转换或填充。

There's quite a concise answer for this question on Quora 关于Quora的这个问题有一个非常简洁的答案

Proxies require support on the engine level and it is not possible to polyfill Proxy. 代理需要在引擎级别上提供支持,并且无法对polyfill Proxy进行支持。

Most major JS engines have yet to implement support. 大多数主要的JS引擎尚未实现支持。 Check out the ECMAScript 6 compatibility table . 查看ECMAScript 6兼容性表

You may want to use Object.observe instead, possibly with polyfills for browsers other than Chrome, but even then the proposal has been withdrawn, and it has been announced it will be removed from Chrome in a future version. 您可能希望使用Object.observe,可能使用Chrome浏览器以外的浏览器进行polyfill,但即使这样,该提案也已撤消,并且已宣布将在未来版本中将其从Chrome中删除。

I personally haven't tried the Object.observe solution but it might be a good place to start. 我个人没有尝试过Object.observe解决方案,但它可能是一个很好的起点。

Good luck! 祝好运!

Direct solution for polyfilling ES6 Proxy in environments without support this feature, of course is impossible - if storing some polyfill function info window.Proxy is meant. 在不支持此功能的环境中直接解决填充ES6代理的问题,当然是不可能的 - 如果存储一些polyfill函数信息window.Proxy的意思。 But if thinking this way, most modern features of ES6 can't be supported, because they will raise syntax error for old-version ECMAScript engine. 但是如果这样思考,ES6的大多数现代功能都无法支持,因为它们会引发旧版ECMAScript引擎的语法错误。

That's why you should use transpiler, which perform preceding wrapping ES6 code into specific constructions, and then evaluate transformed code on old engine. 这就是为什么你应该使用transpiler,它执行前面的ES6代码包装到特定的结构中,然后评估旧引擎上的转换代码。 In current case, just use one Babel plugin: https://www.npmjs.com/package/babel-plugin-proxy 在目前的情况下,只需使用一个Babel插件: https//www.npmjs.com/package/babel-plugin-proxy

Of course, while using this solution, you should configure Webpack to segregate target bundles for different client agents / browsers, depending on it's feature set discovery. 当然,在使用此解决方案时,您应该将Webpack配置为根据其功能集发现来隔离不同客户端代理/浏览器的目标包。 See details here: https://gist.github.com/newyankeecodeshop/79f3e1348a09583faf62ed55b58d09d9 详情请见: https//gist.github.com/newyankeecodeshop/79f3e1348a09583faf62ed55b58d09d9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM