Function's bind() method
The bind() creates a new function whose this value is set to the value that was passed into bind().
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
window.color = "A";
var o = { color: "B" };
function sayColor(){
document.writeln(this.color);
}
var objectSayColor = sayColor.bind(o);
objectSayColor(); //B
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Essential Types
JavaScript Book
Essential Types
Function:
- The Function Type
- Function Declarations versus Function Expressions
- Functions as Values
- Returning a function from a function
- Function arguments
- this for function context
- Function caller
- Function length property
- Function apply()
- Function.call() method
- Function's bind() method
- Function toLocaleString() and toString()