JavaScript Object.prototype.__defineSetter__() Method Last Updated : 10 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The __defineSetter__() method is used to bind an object's property to a function which will be called when an attempt is made to set the specified property. It is recommended to use the object initializer syntax or the Object.defineProperty() API instead of this method as it is being deprecated. Syntax: obj.__defineSetter__( prop, fun ) Parameters: This function accepts two parameters as given above and described below: prop: It is a string that contains the name of the property to bind to the given function.fun: It is a function to be called when there is an attempt to set the specified property. The val parameter of the function can be used to specify an alias for the variable that holds the value attempted to be assigned to the prop. Return Values: This method returns undefined. Example 1: Using the __defineSetter__() method JavaScript <script> let tmpObj = {}; tmpObj.__defineSetter__('setValue', function(val) { this.currentValue = val; }); tmpObj.setValue = 10; console.log(tmpObj.setValue); console.log(tmpObj.currentValue); </script> Output: undefined 10 Example 2: Using the standard-compliant way using object initializer syntax and Object.defineProperty() API JavaScript <script> // Using the set operator var obj1 = { set setValue(val) { this.currentValue = val; } }; obj1.setValue = 10; console.log(obj1.setValue); console.log(obj1.currentValue); // Using Object.defineProperty var obj2 = {}; Object.defineProperty(obj2, 'value', { set: function(val) { this.currentValue = val; } }); obj2.value = 2; console.log(obj2.value); console.log(obj2.currentValue); </script> Output: undefined 10 undefined 2 We have a complete list of Javascript Object Methods, to check those please go through the Javascript Object Complete Reference article. Supported Browsers: ChromeEdgeFirefoxOperaSafari Comment More infoAdvertise with us Next Article JavaScript Object setPrototypeOf() Method T thacker_shahid Follow Improve Article Tags : JavaScript Web Technologies javascript-object JavaScript-Methods Similar Reads JavaScript Object __defineGetter__() Method The __defineGetter__() method is used to bind an object's property to a function which will be called when the specified property is looked up. It is recommended to use the object initializer syntax or the Object.defineProperty() API instead of this method as it is being deprecated. Syntax: obj.__de 2 min read JavaScript Object setPrototypeOf() Method The Object.setPrototypeOf() method in JavaScript is a standard built-in object thatthat will sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.Syntax:Object.setPrototypeOf(obj, prototype)Parameters:This method accepts two parameters as men 2 min read JavaScript Object defineProperties() Method The Object.defineProperties() method in JavaScript is a standard built-in Object that defines a new or modifies existing properties directly on an object and it returns the object.Syntax:Object.defineProperties(obj, props) Parameters:Obj: This parameter holds the object on which the properties are g 2 min read JavaScript Object defineProperty() Method The Object.defineProperty() method in JavaScript is a Standard built-in object which defines a new property directly on an object or it can also modify the existing property of an object and return the object. Syntax:Object.defineProperty(obj, prop, descriptor)Parameters:This method accepts three pa 3 min read JavaScript Object.prototype.valueOf() Method In JavaScript, the Object.prototype.valueOf() method is used to return the primitive value of the specified object. Whenever a primitive value is required, JavaScript automatically invokes the valueOf() method. The valueOf() method is automatically inherited by every object in JavaScript. Every obje 2 min read JavaScript Object.prototype.toString() Method In JavaScript, the Object.prototype.toString() method is used to return a string that can represent the object. The toString() method is automatically inherited by every object which is inherited from Object. Whenever an object is represented as a text value or a string is expected from the object, 3 min read Like