nazerke
7/19/2015 - 2:58 PM

Another example of default binding of "this" keyword

Another example of default binding of "this" keyword

<!DOCTYPE html>
<html>
  <head>
  <script>
  function foo(){
    var bar = "bar1";
    baz();//doesn't matter where the function is called for. When undecorated or 
          //iife it will abide by default binding rule
  }
  function baz(){
    console.log(this.bar);
  }
  var bar = "bar2";
  foo();//bar2;
</script>
  </head>
  <body>
    <!-- page content -->
  </body>
</html>