37

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.

brillout
  • 7,804
  • 11
  • 72
  • 84
  • 1
    A short search shows that there is [github: GoogleChrome/proxy-polyfill](https://github.com/GoogleChrome/proxy-polyfill). You at least should refer to this one and say why it is not sufficient. – t.niese Jul 24 '17 at 17:05
  • 1
    @t.niese It doesn't support catch-all property getters, i.e. wildcard traps. But catch-all traps are one of the most exciting features of Proxy objects. As for referring current attempts I'm considering replying to my own question. – brillout Jul 24 '17 at 17:18
  • 11
    Proxy is a brand new engine-level feature of ES6, there is no way to polyfill it. You'd have to drop IE11 support. – loganfsmyth Jul 24 '17 at 17:20
  • 5
    @loganfsmyth Actually, you could write a babel plugin to change every `object.prop = 1` to `set(object, 'prop', 1)` and every `object.prop` to `get(object, 'prop')`. So it isn't impossible but the problem is the performance drawback coming with it. (I don't know how bad it would be though.) – brillout Jul 24 '17 at 17:25
  • 2
    Right but that's not a polyfill, that's syntax transformation. It would also fail if you use computed properties anywhere in your code. – loganfsmyth Jul 24 '17 at 17:32
  • @loganfsmyth Syntax transformation instead of polyfill is totally fine, especially nowadays with Babel's widespread use. What's the problem with computed properties? – brillout Jul 28 '17 at 07:33
  • 1
    The computed property mention was a mistake on my part, I assumed something incorrectly. I think if you need to support IE11 though, you're just going to have a really hard time with this. You can hack up your code all you want with syntax transforms, but converting every property access to a function call is gonna slow down your code tons, and your codebase will be super hard to maintain for anyone who doesn't know all the details of the transforming you're doing. Using proxy-like behavior seems like a super bad idea to me if you don't have real support for it. – loganfsmyth Jul 28 '17 at 16:28
  • 2
    I'd barely recommend _real_ proxy objects right now because they are known to be pretty slow because they aren't optimized much by engines yet. – loganfsmyth Jul 28 '17 at 16:30
  • @brillout.com No reason for manual plugin writing, just use existing one https://www.npmjs.com/package/babel-plugin-proxy - and maybe fork and update it – Vladislav Ihost Aug 23 '17 at 14:29
  • I wouldn't worry about this for the same reason I won't worry about IE 5.5. It's a dead browser. It's deader in fact because it never will be updated on the IE track. Instead, support Edge, which IS the update and continuation of IE. – Ryan Hanekamp Jan 02 '18 at 19:15
  • @RyanHanekamp IE11 has still a considerable market share and it doesn't seem to be dropping much – brillout Jan 02 '18 at 21:27
  • There are many, many, many things I'm not waiting for 2025 to get non-transpiled browser support. Just because MS keeps its security updated doesn't mean that even they recommend actually using it. It might be rude to say "go get a real browser like Chrome," but it's valid to tell the user that they must at least use Edge. – Ryan Hanekamp Jan 02 '18 at 21:48
  • 1
    IE11 support is ending now (in 2020): https://learn.microsoft.com/en-us/lifecycle/announcements/m365-ie11-microsoft-edge-legacy – vinyll Dec 04 '20 at 15:09
  • @vinyll love it – brillout Dec 05 '20 at 13:30

3 Answers3

20

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.

Dolf Barr
  • 509
  • 4
  • 13
  • 4
    I'm looking for a IE11 polyfill not for a ES5 pollyfill, as stated several times in the OP. And the library you mention doesn't support catch-all getters. And again, the OP explicitly mentions interest in catch-all getters. – brillout Aug 02 '17 at 16:55
  • 5
    As i remember and understand right, according to babel team, it's impossible to fully implement proxy polyfill due to limitations of ES5 (which is used by ie11 as well), Proxies should be implemented on engine level. That's what i was trying to explain, when i'm talking that this lib is best what you can get. More here: [comment on github in babel](https://github.com/babel/babel/issues/71#issuecomment-59113761), [similar question on quora](https://www.quora.com/Is-there-a-way-to-implement-a-ES6-proxy-under-ES5) – Dolf Barr Aug 03 '17 at 10:02
  • Also, similar questions: https://stackoverflow.com/questions/2357618/is-there-such-a-thing-as-a-catch-all-key-for-a-javascript-object https://stackoverflow.com/questions/994143/javascript-getter-for-all-properties – Dolf Barr Aug 03 '17 at 10:06
  • 1
    And accroding to you question - maybe it should be "how to implement a catch-all interceptor with IE11 compatibility" rather than "ES6 Proxy Polyfill for IE11"? – Dolf Barr Aug 03 '17 at 10:09
  • 1
    Accourding to the [GoogleChrome/proxy-polyfill support](https://github.com/GoogleChrome/proxy-polyfill#supports) section, this should work with **ie9+** – Will Farley Mar 21 '18 at 18:04
9

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

Community
  • 1
  • 1
George
  • 1,706
  • 1
  • 11
  • 12
-5

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

Vladislav Ihost
  • 2,127
  • 11
  • 26
  • 1
    Transpilers can't help you if there is no working polyfill. The plugin you pointed to uses a combination of a transpiler and a polyfill that rewrites *all* property access to go via the proxy, which will be hideously slow. – Gordon Leigh Aug 14 '18 at 19:29