<!DOCTYPE html>
<html>
<head>
<meta name="description" content="explicit this binding in jssecond approach">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function bind(fn, o) {
return function() {
fn.call(o);
};
}
function foo() {
console.log(this.bar);
}
var obj = {bar: 'bar'}, obj2 = {bar: 'bar2'};
foo = bind(foo, obj);
foo();
foo.call(obj2);
</script>
<script id="jsbin-source-javascript" type="text/javascript">function bind(fn, o) {
return function() {
fn.call(o);
};
}
function foo() {
console.log(this.bar);
}
var obj = {bar: 'bar'}, obj2 = {bar: 'bar2'};
foo = bind(foo, obj);
foo();
foo.call(obj2);</script></body>
</html>