我已经看了很长时间的这种行为,有几分钟的停机时间,并且我以为我会问这个问题。
我在这里完成了一个codepen:
http://codepen.io/ShashankaNataraj/pen/eZEYRZ?editors=1010
它是一个JS代码块,没有任何花哨,问题是我不明白的奇怪行为:
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);
}
});
就像我在上面的评论中所说,如果console.log
语句被取消注释,浏览器控制台就可以解析$scope
和$scope.sample
就好了!是什么给了什么?!
最初我假设这是由于一些与闭包相关的行为,但奇怪的是,这似乎是非角度代码的情况