Using ES6's Proxy for safe Object property access

Gidi Meir Morris
2 min readFeb 7, 2016

--

I can’t get over the feeling that ES6 (still refusing to say ES2015 ^_^) is a kind of playground offering me all these new toys and attractions to play around with.
Currently my focus is on exploring the Proxy object which gives us a new way to intercept fundamental operations on Objects, among them property access, which is something I want to play around with today.

TL/DR

Sick and tired of accessing a nested object under a property in a deep object just to have the Uncaught TypeError: Cannot read property ‘foo’ of undefined thrown in your face?
Well, by using a Proxy you can get around those errors without excessive key checking in a reusable manner.
The code example for doing this is down bellow, an npm module is available via npm install safeobj, with the source on Github.

Please continue reading at: http://gidi.io/2016/02/07/using-es6-s-proxy-for-safe-object-property-access.html

I’m No Longer Blogging On Medium

I love Medium and I think they’re doing some great things, but I’ve reached a point where the limitations of Medium are getting in the way of my blogging goals.

You’re hereby invited to read my content on my personal blog at: Gidi.io

You Can Read The Original Article Here:

http://gidi.io/2016/02/07/using-es6-s-proxy-for-safe-object-property-access.html

--

--