JavaScript handler.defineProperty() Method

The handler.defineProperty() method can define the new properties. It can also modify the existing properties directly on an object. It is trap for Object.defineProper(). This method can be used in two situations.

  1. When we wanted to ensure cross-browser support of getters and setters.
  2. Whenever we want to define a custom property accessor.

Syntax

Parameters

Target: The target object.

Property: Retrieved property description.

Descriptor: The property being defined or modified.

Return value

This method returns a Boolean

Browser Support

Chrome49
Edge12
Firefox18
Opera36

Example 1

Test it Now

Output:

[object Object]

Example 2

Test it Now

Output:

in defineProperty

Example 3

Test it Now

Output:

Learn Java Script Proxt Method





Latest Courses