What is the difference between angular.copy() and an assignment (=)?

前端 未结 5 867
遇见更好的自我
遇见更好的自我 2020-12-02 17:02

I want to assign some values when a button click event happens via event parameter:

$scope.update = function(context) {
    $scope.master = context;
};
         


        
5条回答
  •  渐次进展
    2020-12-02 17:47

    When you manipulate primitive types (like int) in Javascript, = and angular.copy are the same as any assignment results in copying the value of the variable.

    When you manipulate objects in Javascript, = assign a reference to the existing object to the variable and angular.copy is copying, that means creating a new object with the same properties and values and assigning the new object's reference to the variable.

提交回复
热议问题