InterviewSolution
Saved Bookmarks
| 1. |
What are Proxy in ES6? |
|
Answer» The proxy objects are used to customize behaviour for BASIC operations like property lookup, ASSIGNMENT, enumeration, function invocation, etc. For basic ACTIONS, the Proxy object is used to create custom behaviour (e.g. property lookup, assignment, enumeration, function invocation, etc). We need to define three crucial terms:
Example: const handle = { get: function(ob, prp) { return prp in ob ? ob[prp] : 37; }};const x = new Proxy({}, handle);x.a = 2;x.b = undefined;console.log(x.a, x.b); // 2, undefinedconsole.log('c' in x, x.c); // false, 37Proxies have a WIDE RANGE of real-world applications.
|
|