DEV Community


Discussion on: Optional Chaining in JavaScript Right Now!

karataev profile image
Eugene Karataev

This is a clever use of Proxy to safely access object properties ✨

What do you think about lodash way to get object properties? It solves the same problem, but in different way.

var obj = {foo: {bar: 'baz'}};
_.get(obj, ''); // baz
_.get(obj, 'lol.kek'); // undefined
samholmes profile image
Sam Holmes Author

This approach is reasonable. It comes down to style really. Using Proxies allows you to tap into some meta-programming aspects of JavaScript where you can change the behavior or the syntax slightly. Either way you accomplish this is fine, however Proxies seems like a nicer use case.