CodesJava

Easy learning with example program codes

JavaScript Function bind() method

The JavaScript Function bind() method creates a new function.

Syntax:

function.bind (thisArg [arguments])

Parameters:
thisArg: It is used as this keyword for the call to a function.
arguments: It represents the function parameters.

Return:
A new function which will be the replica of calling function.

Example:

<!DOCTYPE html>
<html>
<body>
<script>  
var jewel =
{  
stone: "DIAMOND",  
getjewel: function()
{  
return this.stone;  
}  
}  
var getjewel1 = jewel.getjewel;  
var getjewel2 = getjewel1.bind(jewel);  
document.writeln(getjewel2());  
</script>  
</body>
</html>

Output:

DIAMOND
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status