JavaScript Object __defineGetter__() Method Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report 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.__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. Example 1: Using the __defineGetter__ () method JavaScript let obj = {}; obj.__defineGetter__('printTen', function () { return 10; }); console.log(obj.printTen); Output: 10 Example 2: Using the standard-compliant way using object initializer syntax and Object.defineProperty() API. JavaScript // Using the get operator let obj = { get printTen() { return 10; } }; console.log(obj.printTen); // Using Object.defineProperty let obj1 = {}; Object.defineProperty(obj1, 'printTwo', { get: function () { return 2; } }); console.log(obj1.printTwo); Output: 10 2 We have a complete list of Javascript Object Methods, to check those please go through the Javascript Object Complete Reference article. Supported Browser: Chrome 1 and aboveEdge 12 and aboveFirefox 1 and aboveInternet Explorer 11 and aboveOpera 9.5 and aboveSafari 3 and above Create Quiz Comment T thacker_shahid Follow 2 Improve T thacker_shahid Follow 2 Improve Article Tags : JavaScript Web Technologies javascript-object JavaScript-Methods Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like