Proxy Pattern in JavaScript

Just a catch up about how the Proxy object works on JavaScript to allow us to implement Proxy patterns.

? JavaScript’s Proxy object allows us to intercept and modifies any JavaScript object.

? JavaScript’s Proxy object is an elegant and safe way for …


This content originally appeared on DEV Community and was authored by Beto Muniz

Just a catch up about how the Proxy object works on JavaScript to allow us to implement Proxy patterns.

? JavaScript's Proxy object allows us to intercept and modifies any JavaScript object.

? JavaScript's Proxy object is an elegant and safe way for creating or extending libraries, caching, error handling, and complex data manipulation on JavaScript.

const obj = {a: 1, b: 2};

const arrProxy = new Proxy(obj, {
  get: function (item, property) {
    if (item.hasOwnProperty(property)) return item[property];

    return "default value";
  },
});

arrProxy.z; // "default value"
arrProxy.a; // 1

? What are the use cases that you most liked to use such a JavaScript feature?

? Still, for a detailed API spec of Proxy's object in JavaScript, take a look in the MDN docs.

? If you thought this brief content useful for your web dev studies and want to receive more, subscribe to my newsletter


This content originally appeared on DEV Community and was authored by Beto Muniz


Print Share Comment Cite Upload Translate Updates
APA

Beto Muniz | Sciencx (2021-05-03T21:03:24+00:00) Proxy Pattern in JavaScript. Retrieved from https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/

MLA
" » Proxy Pattern in JavaScript." Beto Muniz | Sciencx - Monday May 3, 2021, https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/
HARVARD
Beto Muniz | Sciencx Monday May 3, 2021 » Proxy Pattern in JavaScript., viewed ,<https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/>
VANCOUVER
Beto Muniz | Sciencx - » Proxy Pattern in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/
CHICAGO
" » Proxy Pattern in JavaScript." Beto Muniz | Sciencx - Accessed . https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/
IEEE
" » Proxy Pattern in JavaScript." Beto Muniz | Sciencx [Online]. Available: https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/. [Accessed: ]
rf:citation
» Proxy Pattern in JavaScript | Beto Muniz | Sciencx | https://www.scien.cx/2021/05/03/proxy-pattern-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.