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.
obj.__defineGetter__( prop, func )
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 the property is looked up.
Return Values: This method returns undefined.
The below examples illustrate the usage of __defineGetter__() method:
Example 1: Using the __defineGetter__ () method
Example 2: Using the standard-compliant way using object initializer syntax and Object.defineProperty() API.
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 11 and above
- Opera 9.5 and above
- Safari 3 and above