AngularJS $watch vs $watchCollection: which is better for performance?

前端 未结 3 2014
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 19:46

For watching an object scope variable, is $scope.$watch with objectEquality set to true OR $scope.$watchCollection better?

For

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 20:34

    The $watchCollection() function is a sort-of mid-ground between the two $watch() configurations above. It's more in-depth than the vanilla $watch() function; but, it's not nearly as expensive as the deep-equality $watch() function. Like the $watch() function, the $watchCollection() works by comparing physical object references; however, unlike the $watch() function, the $watchCollection() goes one-level deep and performs an additional, shallow reference check of the top level items in the collection.

    see this explanation

提交回复
热议问题