JavaScript preventExtensions() method

The Javascript handler preventExtensions() method traps the Object.preventExtensions method. New properties can not be added to the object when extensions are prevented. Syntax: preventExtensions: function(target) Parameters: target: It represents the target object. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> const handler = new Proxy({}, { preventExtensions: function(a) { Object.preventExtensions(a); return !Object.isExtensible(a); }}); document.writeln(‘Value: ‘); … Read more

JavaScript ownKeys() method

The Javascript handler ownKeys() method gives an enum object in return. Syntax: ownKeys: function(target) Parameters: target: It represents the target object. Return: An enumerable object. Example: <!DOCTYPE html> <html> <body> <script> var handler = new Proxy({}, { ownKeys: function(a) { document.writeln(” My favourite fruits are: “); return [‘apple’, ‘mango’, ‘and orange.’]; }}); document.writeln(Object.getOwnPropertyNames(handler)); </script> </body> … Read more

JavaScript isExtensible() method

The Javascript handler isExtensible() method traps for Object.isExtensible(). It is commonly used for logging or auditing calls. Syntax: isExtensible: function(target) Parameters: target: It represents the target object. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> const handler={ too:1 } const extent = new Proxy(handler, { isExtensible: function(a) { document.writeln(‘HELLO WORLD! : ‘); return true; }}); … Read more

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