【发布时间】:2014-05-24 15:47:38
【问题描述】:
即使使用 cmets,我也很难理解以下代码
// Store the initial cell value so we can reset to it if need be
var oldCellValue;
var dereg = scope.$watch('ngModel', function() {
oldCellValue = ngModel.$modelValue;
dereg(); // only run this watch once, we don't want to overwrite our stored value when the input changes
});
在这种情况下,函数 dereg 被调用了多少次?这是递归吗?
【问题讨论】:
-
这很容易找到,只需在代码中放置一个断点即可。
-
你好,递归。递归,你好!
-
这与递归无关。 (也就是说,实现似乎有问题,不太可能按预期工作。)
-
@ExpertSystem 确实如此。看了文档发现dereg跟watch方法本身没有关系,其实是watch方法返回的注销函数。
标签: javascript angularjs function watch