angular.copy() doesn't strip $$hashKey
angular.copy({ name: "DEF", $$hashKey: "089" }); => Object { name= "DEF", $$hashKey= "089" }
I believe it is suppose to strip out $$hashKey, like:
angular.fromJson(angular.toJson({ name: "DEF", $$hashKey: "089" })); => Object { name= "DEF" }
Why aren't the two equivalent?
I guess it probably should since the idea is that each object has a unique $$hashKey and now you have to potentially diverging objects with the same key. @IgorMinar & @mhevery - Any thoughts on this?
With the new change to ng-repeat 1.1.4 that prevents duplicates, this break my code.
My use-case is a simple array, where the user can drag a cell onto another cell to copy it. Now the copy creates a duplicate because the key is copied as well.
For now, I'm just overriding angular.copy with my own version that deletes the hashkey, because there are just too many places in my code where I copy objects.
BTW: extend() also copies the hashkey.
I've just commented on that patch, and it occurred to me that the use of hashKey() is kind of confused. First, hashKey() is a misnomer, because
- the documentation says "...Computes a hash of an 'obj'..."
- the resulting hash value is used as if two objects with the same hash are equal.
It is true that objects that are equal must have the same hash value, but the reverse is not true. A more appropriate function would be getObjectID or assignObjectID.
Since the "hash" is really used as an object identity value, it makes no sense to copy() or extend() it to another object, ever.
I kind of think that this needs to be addressed, because it will generate subtle problems in any larger application that will be difficult to track down.
I think I have an idea for a patch that might work and should be less intrusive (i.e. not drop all $ properties).
For better understanding on angular.copy() visit this article http://sharepoint-2010-world.blogspot.in/2013/10/angularcopy-in-angularjs.html
Just use angular.toJson(obj) to get rid of the $$hashKey's