Open In App

JavaScript Object.prototype.__lookupSetter__() Method

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:

Return value:



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




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

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.

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

Example 2: 




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

Output
GeeksforGeeks

Supported Browsers:

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


Article Tags :