I have library code does a simple function assignment. This function is accessed from the global scope.
When I add "use strict"
at the beginning of the file, I get an error TypeError: a is undefined
, on assignment to a.b
.
"use strict"; /* Remove this and 'a' is defined */
(function() {
var a = this;
a.b = function() {
document.getElementById('test').innerHTML = 'abc';
};
})();
b();
<div id="test"></div>
Why do I get this error considering that var a
is declared on the previous line?