JavaScript Proxy Complete Reference
JavaScript Proxy() Object is used to define the custom behavior of fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).
Syntax:
const p = new Proxy(target, {
Proxy method: function(target, thisArg, argumentsList) {
}
});Example: Below examples illustrate the handler.apply() method in JavaScript:
Javascript
<script> function sum(a, b) { return a + b; } const handler = { apply: function(target, thisArg, argumentsList) { console.log(`Calculate sum: ${argumentsList}`); return target(argumentsList[0], argumentsList[1])*14/3; } }; const proxy1 = new Proxy(sum, handler); console.log(sum(23, 4)); console.log(proxy1(23, 4));</script> |
Output:
27 "Calculate sum: 23, 4" 126
The complete list of JavaScript Proxy is listed below:
Proxy Methods:
JavaScript Proxy Methods | Description |
|---|---|
| JavaScript handler.apply() Method | The handler.apply() method in JavaScript is used as a trap for a function call. |
| JavaScript handler.construct() Method | The handler.construct() method in JavaScript is a trap for the new operation and this method returns an object. |
| JavaScript handler.defineProperty() Method | The handler.defineProperty() method in Javascript is used to define the new properties and to modify the existing properties directly on an object. |
| JavaScript handler.deleteProperty() Method | The handler.deleteProperty() method in JavaScript is a trap for the delete operator. |
| JavaScript handler.get() Method | The handler.get() method in JavaScript is a trap for getting a property value. |
| JavaScript handler.getOwnPropertyDescriptor() Method | The handler.getOwnPropertyDescriptor() method in Javascript is a trap for Object.getOwnPropertyDescriptor() method. |
| JavaScript handler.getPrototypeOf() Method | The handler.getPrototypeOf() method in JavaScript is a trap for the internal method. |
| JavaScript handler.has() Method | The handler.has() method in JavaScript is used to “hide” any property that you want. |
| JavaScript handler.isExtensible() Method | The handler.isExtensible() method in JavaScript is a trap for Object.isExtensible() method and it returns a boolean value. |
| JavaScript handler.ownKeys() Method | The handler.ownKeys() method in JavaScript is a trap for Reflect.ownKeys() method and this method returns an enumerable object. |
| JavaScript handler.preventExtensions() Method | The handler.preventExtensions() method in JavaScript is a trap for Object.preventExtensions() method and it returns a boolean value. |
| JavaScript handler.set() Method | The handler.set() method in JavaScript is a trap for setting a property value. This method returns a boolean value. |
| JavaScript handler.setPrototypeOf() Method | The handler.setPrototypeOf() method in JavaScript is a trap for Object.setPrototypeOf() method and it returns a Boolean value. |






Please Login to comment...