ES6 Proxy Polyfill for IE11

这一生的挚爱 提交于 2019-12-30 01:36:38

问题


IE11 does not and will not implement ES2015 Proxy objects. Yet IE11's end of extended support is October 14, 2025.

Is there any way to polyfill Proxy objects for IE11? All other browsers support Proxy already.

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.

Edit2: I'm particularly interested in being able to implement a catch-all interceptor. Similar to __getattr__ in Python. It only has to work in IE11.


回答1:


Best you can get is github: GoogleChrome/proxy-polyfill

According to Babel docs:

Due to the limitations of ES5, Proxies cannot be transpiled or polyfilled.




回答2:


There's quite a concise answer for this question on Quora

Proxies require support on the engine level and it is not possible to polyfill Proxy.

Most major JS engines have yet to implement support. Check out the ECMAScript 6 compatibility table.

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.

I personally haven't tried the Object.observe solution but it might be a good place to start.

Good luck!

EDIT: Thank you to Matt Jensen in the comments for pointing out there is infact a way to polyfill some parts of ES6 Proxy using this package: github.com/GoogleChrome/proxy-polyfill

AWESOME




回答3:


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

That's why you should use transpiler, which perform preceding wrapping ES6 code into specific constructions, and then evaluate transformed code on old engine. In current case, just use one Babel plugin: 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. See details here: https://gist.github.com/newyankeecodeshop/79f3e1348a09583faf62ed55b58d09d9



来源:https://stackoverflow.com/questions/45285992/es6-proxy-polyfill-for-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!