JavaScript Proxy() Constructor Last Updated : 22 May, 2023 Comments Improve Suggest changes Like Article Like Report JavaScript proxy() constructor is used to return the proxy constructor function for the object(e.g. property lookup, assignment, enumeration, function invocation, etc). Syntax: let p = new Proxy(target, handler); Parameter: The proxy object accept two parameters as mentioned above and described below: target: A target object (can be any sort of object including a function, class, or even another proxy) to wrap with Proxy.handler: An object whose properties are functions which define the behavior of the proxy when an operation is performed on it. Example: HTML const Person = { Name: 'John Nash', Age: 25 }; const handler = { // target represents the Person while prop represents // proxy property. get: function (target, prop) { if (prop === 'FirstName') { return target.Name.split(' ')[0]; } if (prop === 'LastName') { return target.Name.split(' ').pop(); } else { return Reflect.get(target, prop); } } }; const proxy1 = new Proxy(Person, handler); console.log(proxy1); // Though there is no Property as FirstName and LastName, // still we get them as if they were property not function. console.log(proxy1.FirstName); console.log(proxy1.LastName); Output: [object Object] John Nash Note: The above code can be run directly in terminal provided NodeJs is installed, else run it in a HTML file by pasting the above in script tag and check the output in console of any web browser. Comment More info I imdhruvgupta Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Constructors JavaScript-Proxy/handler +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like