I have been seeing this behaviour for a long time, had a few minutes of downtime and thought I'd ask this question.
I have a codepen done here:
http://codepen.io/ShashankaNataraj/pen/eZEYRZ?editors=1010
Its a block of JS code, nothing fancy, problem is there is weird behaviour I don't understand:
angular.module('helloWorld',[])
.controller('HelloWorldController',function($scope){
$scope.sample = 'abc';
$scope.clickHandler = function(){
/**
* When this debugger hits, try to type in $scope or $scope.sample in the console,
* the console will fail to resolve $scope too with the error:
* VM646:1 Uncaught ReferenceError: $scope is not defined(…)
*/
debugger;
/**
* As soon as the below console.log statement is uncommented, when the debugger above hits,
* if one types in $scope or $scope.sample in the console, it gets resolved!
*
*/
//console.log($scope.sample);
}
});
Like I said in the comments above, if the console.log
statement is uncommented, the browsers console is able to resolve $scope
and $scope.sample
just fine! What gives?!
Initially I was under the assumption that this was due to some closure related behaviour, but weirdly, this seems to be the case with non angular code as well