angular.copy()和分配之差(=) [英] Difference between angular.copy() and assignment (=)
问题描述
我要分配一些值时,通过事件参数按钮单击事件
I want to assign some values when a button click event via event parameter
$scope.update = function(context) {
$scope.master = context;
};
我已指定用户
值 $ scope.master
现在我看到 angular.copy()。所以我写了code。与 angular.copy 。
Now i am seeing angular.copy(). So i wrote the code with angular.copy.
$scope.update = function(context) {
$scope.master = angular.copy(context)
};
两者都在做相同的,那么有什么区别?请告诉 angular.copy之间的差值()
和等号(=)
。
推荐答案
既然可以这里读一> angular.copy()
执行深拷贝的说法(参见克隆) - 本质上是创建一个新的对象 - 而使用赋值运算符 =
刚刚分配的参考的的。
As can be read here angular.copy()
performs a deep copy (cf. "clone") of the argument - essentially creating a new object - whereas using the assignment operator =
just assigns reference's.
因此,在后一种情况下,如果我们改变 $ scope.master
的东西你也会改变背景
。
Thus in the latter case, if you we're to change something in $scope.master
you would also change context
.
干杯,
这篇关于angular.copy()和分配之差(=)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!