Javascript: why “this” inside the private function refers to the global scope?
Consider the following code: function A() {} A.prototype.go = function() { console.log(this); //A { go=function()} var f = function() { console.log(this); //Window }; f(); } var a = new A(); a.go(); Why does 'this' inside function 'f' refers to the global scope? Why it is not the scope of function 'A' ? JavaScript has a different concept of what the special name this refers to than most other programming languages do. There are exactly five different ways in which the value of this can be bound in the language. The Global Scope this; When using this in global scope, it will simply refer to the