function bind
Description
function bind()
method creates a new
function instance whose this value is bound to the value that was passed into bind()
.
Example
<!-- w w w. j a v a 2 s .c o m-->
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.myName = "XML";
var o = { myName: "CSS" };
function printMyName(){
console.log(this.myName);
}
var bindedPrintMyName = printMyName.bind(o);
bindedPrintMyName(); //CSS
</script>
</head>
<body>
</body>
</html>
bindedPrintMyName() is created from printMyName() by calling bind() and
passing in the object o. this value in bindedPrintMyName() points to o
.
Calling bindedPrintMyName() in global context outputs "CSS" .