Javascript 带有angularjs断点的奇怪chrome调试器行为
我已经看到这种行为很长时间了,有几分钟的停机时间,我想我会问这个问题 我在这里做了一个代码笔: 这是一段JS代码,没什么特别的,问题是有一种奇怪的行为我不明白:Javascript 带有angularjs断点的奇怪chrome调试器行为,javascript,angularjs,google-chrome,google-chrome-devtools,Javascript,Angularjs,Google Chrome,Google Chrome Devtools,我已经看到这种行为很长时间了,有几分钟的停机时间,我想我会问这个问题 我在这里做了一个代码笔: 这是一段JS代码,没什么特别的,问题是有一种奇怪的行为我不明白: angular.module('helloWorld',[]) .controller('HelloWorldController',function($scope){ $scope.sample = 'abc'; $scope.clickHandler = function(){ /** * When t
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
很好!什么给了我
起初,我假设这是由于一些闭包相关的行为,但奇怪的是,非角度代码也是如此
@dandavis这如何解释控制台在click处理程序中至少引用一次scope变量时解析该变量?请查看此答案:对于第二个代码笔链接,我可以在chrome中重现该问题,但不能在firefox中重现。也许这是一个特定于浏览器的bug?(编辑:nevermind上面Erik的评论解释了这一点,我想在撰写本文时,Firefox没有实现这个v8优化?)。已删除。我无法重新创建accepted answer:描述的“eval”行为,但我认为答案仍然有意义。@dandavis这如何解释控制台在click处理程序中至少引用一次scope变量时解析该变量的原因?请查看此答案:对于第二个链接的代码,我可以在chrome中重现这个问题,但在firefox中却不行。也许这是一个特定于浏览器的bug?(编辑:nevermind上面Erik的评论解释了这一点,我想在撰写本文时,Firefox没有实现这个v8优化?)。已删除。我无法重新创建已接受答案描述的“eval”行为:,但我认为答案仍然有意义。