Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Object.prototype.__lookupSetter__() Method

  • Difficulty Level : Expert
  • Last Updated : 25 May, 2021

The JavaScript Object.prototype.__lookupSetter__ () method is used to get a reference to the setter function when it was defined for a property of an object. It was not possible to refer to the setter function through that property because it refers to the function’s return value. It returns the function that is bound to the specified property as a setter.

Syntax:

O.prototype.__lookupSetter__ (P)

Terminology:

  • O: It refers to Object(this value). Object accepts the argument value. It converts the argument to an object value.
  • P : It refers to a string key that is generated from the property (P). It refers to the name of the property that should be returned by the setter.

 



Return value:

  • Returns undefined if object O is null or IsAccessorDescriptor is false.
  • If the object O is not null and IsAccessorDescriptor is true, the function bound as a setter to the specified property is returned.

Example 1:  It returns a function named gfg().

Javascript




<script>
const gfgObject = {
  set gfg(arg) {
    this.portalName = arg;
    console.log(portalName)
  }
};
  
const gfgFunction = gfgObject.__lookupSetter__('gfg')
gfgFunction("GeeksforGeeks");
</script>

Output:

GeeksforGeeks

Web standards no longer recommend this feature. Though it is still supported by some browsers, such as Google Chrome, it is being phased out. It should not be used in any new or old project. It is possible that pages or web apps that rely on it will fail any time.

It is recommended to use Object.getOwnPropertyDescriptor().set, which takes two parameters.

  • Object in which the property should be sought.
  • Name of the property from which the description is to be retrieved.

Note: It returns the function that serves as the property’s setter, or undefined if there is no setter.

Example 2: 

Javascript




<script>
const gfgObject = {
  set gfg(arg) {
    this.portalName = arg;
    console.log(portalName)
  }
};
const gfgFunction =  
  Object.getOwnPropertyDescriptor(gfgObject,"gfg").set
gfgFunction("GeeksforGeeks");
</script>

Output:

GeeksforGeeks

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox

Note:This function has been DEPRECATED and no longer recommended.




My Personal Notes arrow_drop_up
Recommended Articles
Page :