JavaScript Object.prototype.__lookupGetter__() method returns a function that is bound to the specified property as a getter. This method is although not recommended using and it is now deprecated.
Syntax:
__lookupGetter__(sprop)
Parameters: sprop is a string representing the name of the property whose getter would be returned.
Return Value: It returns a function bound to the specified property.
Below are some examples of how to use this method.
Example 1:
Javascript
<script>
var cal = {
get add() {
var x=8;
var y=10;
return x+y;
}
}
console.log( typeof (cal.__lookupGetter__( 'add' )));
</script>
|
Output:
function
Example 2:
Javascript
<script>
var cal = {
get add() {
var x = 8;
var y = 10;
return x + y;
},
get multiply() {
var x = 8;
var y = 10;
return x * y;
}
}
console.log(cal.__lookupGetter__( 'add' )());
console.log(cal.__lookupGetter__( 'multiply' )());
</script>
|
Output:
18
80
The __lookupGetter() method is returning the function add() and multiply() that are bound as getter.