JSFiddle

  • hard binding 2

    No-Library (pure JS), HTML, CSS, JavaScript

    function bind(fn,o) {
    	return function(){
    		fn.call(o);
    	};
    }
    function foo() {
    	console.log(this.bar);
    }
    
    var obj = { bar: "bar" };
    var ...
  • hard binding #4 is the latest revision

    No-Library (pure JS), HTML, CSS, JavaScript

    function foo() {
    	console.log(this.bar);
    }
    
    var obj = { bar: "bar" };
    var obj2 = { bar: "bar2" };
    
    var orig = foo;
    foo = function(){ orig ...
  • explicit binding

    No-Library (pure JS), HTML, CSS, JavaScript

    function foo() {
    	console.log(this.bar);
    }
    
    var bar = "bar1";
    var obj = { bar: "bar2" };
    
    foo();			// "bar1" will get UNDEFINED in strict ...
  • This : implicit & default binding 2

    No-Library (pure JS), HTML, CSS, JavaScript

    var o1 = {
    	bar: "bar1",
    	foo: function() {
    		console.log(this.bar);
    	}
    };
    var o2 = { bar: "bar2", foo: o1.foo };
    
    var bar = "bar3 ...
  • This :implicit & Default binding

    No-Library (pure JS), HTML, CSS, JavaScript

    function foo() {
    	console.log(this.bar);
    }
    
    var bar = "bar1";
    var o2 = { bar: "bar2", foo: foo };
    var o3 = { bar: "bar3", foo ...
  • Hoisting Recursion

    Whats the final number

    console.log(a(1));
    
    function a(foo){
           if(foo>20) return foo;
            return b(foo+2);
    }
    function b(foo){
        return ...
  • Function Hoisting

    Which one of these three definitions of foo win ?

    foo(); // "foo"
    
    var foo = 2;
    
    function foo() {
    	console.log("bar");
    }
    
    function foo() {
    	console.log("foo");
    }
    
  • Hoisting

    the Compiler for js runs the var first hence why you get a undefined and not a reference error

    console.log(a);
    console.log(b);
    var a= b;
    var b = 2;
    console.log(b);
    console.log(a);