angular.copy fails for objects implementing a forEach that depends on some internal state. #10304
Description
angular.forEach
attempts to use an object's own forEach
function if it is available.
angular.copy
uses Object.create
to make a new empty destination object with the same prototype as the source. angular.copy
then uses angular.forEach
to iterate over the keys of the destination object and delete any properties.
The problem: if a class implements it's own forEach, but that forEach depends on some class property normally initialized in its constructor, then this iteration over the destination's keys will result in an error.
Real example: The Google Closure goog.struct.Map
. This implements its own forEach, but it that forEach depends on the keys_
property to have been initialized in the constructor. Other collections in goog.struct
probably have the same problem.
Running contrived example: http://jsbin.com/qumajeyuse/1/edit?js,console
Running example with goog.struct.Map
: http://jsbin.com/fuvaliboli/2/edit?js,console