MCPcopy Index your code
hub / github.com/angular-ui/ui-router / copy

Function copy

test/angular/1.5/angular.js:887–1025  ·  view source on GitHub ↗

* @ngdoc function * @name angular.copy * @module ng * @kind function * * @description * Creates a deep copy of `source`, which should be an object or an array. * * * If no destination is supplied, a copy of the object or array is created. * * If a destination is provided, all of its element

(source, destination)

Source from the content-addressed store, hash-verified

885 </example>
886 */
887function copy(source, destination) {
888 var stackSource = [];
889 var stackDest = [];
890
891 if (destination) {
892 if (isTypedArray(destination) || isArrayBuffer(destination)) {
893 throw ngMinErr('cpta', 'Can\'t copy! TypedArray destination cannot be mutated.');
894 }
895 if (source === destination) {
896 throw ngMinErr('cpi', 'Can\'t copy! Source and destination are identical.');
897 }
898
899 // Empty the destination object
900 if (isArray(destination)) {
901 destination.length = 0;
902 } else {
903 forEach(destination, function(value, key) {
904 if (key !== '$$hashKey') {
905 delete destination[key];
906 }
907 });
908 }
909
910 stackSource.push(source);
911 stackDest.push(destination);
912 return copyRecurse(source, destination);
913 }
914
915 return copyElement(source);
916
917 function copyRecurse(source, destination) {
918 var h = destination.$$hashKey;
919 var key;
920 if (isArray(source)) {
921 for (var i = 0, ii = source.length; i < ii; i++) {
922 destination.push(copyElement(source[i]));
923 }
924 } else if (isBlankObject(source)) {
925 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
926 for (key in source) {
927 destination[key] = copyElement(source[key]);
928 }
929 } else if (source && typeof source.hasOwnProperty === 'function') {
930 // Slow path, which must rely on hasOwnProperty
931 for (key in source) {
932 if (source.hasOwnProperty(key)) {
933 destination[key] = copyElement(source[key]);
934 }
935 }
936 } else {
937 // Slowest path --- hasOwnProperty can't be called as a method
938 for (key in source) {
939 if (hasOwnProperty.call(source, key)) {
940 destination[key] = copyElement(source[key]);
941 }
942 }
943 }
944 setHashKey(destination, h);

Callers 9

$CoreAnimateCssProviderFunction · 0.70
angular.jsFile · 0.70
$ParseProviderFunction · 0.70
$RootScopeProviderFunction · 0.70
ngModelOptionsDirectiveFunction · 0.70
parseOptionsExpressionFunction · 0.70
handleResponseFunction · 0.70
angular-animate.jsFile · 0.70
queueAnimationFunction · 0.70

Calls 6

isArrayFunction · 0.85
isTypedArrayFunction · 0.70
isArrayBufferFunction · 0.70
forEachFunction · 0.70
copyRecurseFunction · 0.70
copyElementFunction · 0.70

Tested by

no test coverage detected