plastikaweb
9/4/2017 - 6:15 PM

JS Bin explicit this binding in js // source http://jsbin.com/qicehok

JS Bin

explicit this binding in js

// source http://jsbin.com/qicehok

<!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>
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);