JavaScript has() method

The Javascript handler has() method hides the specified property. Syntax: has: function(target, property) Parameters: target: It represents the target object. property: It represents the property to be hidden. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> var handler={x:10} var display = new Proxy(handler, { has: function(a,b) { document.writeln(b); return false; } }); document.writeln(‘Value:’ in display); … Read more

JavaScript getPrototypeOf() method

The Javascript handler getPrototypeOf() method traps for the internal method. Syntax: getPrototypeOf(target) Parameters: target: It represents the target object. Return: An object or null. Example: <!DOCTYPE html> <html> <body> <script> var handler = {}; var arr = new Proxy(handler, { getPrototypeOf(arg) { return Array.prototype; } }); document.write( arr instanceof Array ); </script> </body> </html>

JavaScript getOwnPropertyDescriptor() method

The Javascript handler getOwnPropertyDescriptor() method traps for Object.getOwnPropertyDescriptor(). Syntax: getOwnPropertyDescriptor: function(target, property) Parameters: target: It represents the target object. property: It represents the property whose description should be retrieved. Return: An object or undefined. Example: <!DOCTYPE html> <html> <body> <script> const handler = new Proxy({}, { getOwnPropertyDescriptor: function(a,b) { document.writeln(‘HELLO WORLD!’); return Object.getOwnPropertyDescriptor(a,b); }}); console.dir(Object.getOwnPropertyDescriptor(handler)); … Read more

JavaScript get() method

The Javascript handler get() method traps for getting a property value. Syntax: get: function(target, property, receiver) Parameters: target: It represents the target object. property: It represents the property to be obtained. receiver: It represents the proxy or an object that is inherited from the proxy. Return: Any value. Example: <!DOCTYPE html> <html> <body> <script> var … Read more

JavaScript deleteProperty() method

The Javascript handler deleteProperty() method removes a property entirely from the target object. Syntax: deleteProperty: function(target, property) Parameters: target: It represents the target object. property: It represents the property to be deleted. Return: Returns true if the specified property is deleted successfully otherwise returns false. Example: <!DOCTYPE html> <html> <body> <script> var handler = new … Read more

JavaScript defineProperty() method

The Javascript handler defineProperty() method defines the new properties and often modifies the existing properties. Syntax: defineProperty: function(target, property, descriptor) Parameters: target: It represents the target object. property: It represents the property description. descriptor: It represents the property being defined or modified. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> var handler = {}; var … Read more

JavaScript construct()

The Javascript handler construct() method intercepts a new operation. Syntax: construct: function(target, arguments, newTarget) Parameters: target: It represents the target object. argumentsList: The list of function parameters. newTarget: It represents the constructor. Return: Object. Example: <!DOCTYPE html> <html> <body> <script> var handler = function(text) { this.text = text; }; var print = new Proxy(handler, { … Read more

JavaScript apply() method

The Javascript handler applies () method traps for a function call. Syntax: apply: function(target, thisArg, arguments) Parameters: target: It represents the target object. thisArg: It represents this keyword for the function call. argumentsList: The list of function parameters. Return: Any value. Example: <!DOCTYPE html> <html> <body> <script> var handler = function(a, b) { document.writeln(‘proxy: ‘ … Read more

JavaScript handler

Javascript facilitates a number of handler methods in order to improve the ease of programming. These are: apply() method: Use: To trap for a function call. construct() method: Use: To intercept the new operation. defineProperty() method: Use: To define the new properties and to modify the existing properties. deleteProperty() method: Use: To remove a property … Read more