MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / copy

Function copy

web/static/bower_components/angular/angular.js:866–960  ·  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, stackSource, stackDest)

Source from the content-addressed store, hash-verified

864 </example>
865 */
866function copy(source, destination, stackSource, stackDest) {
867 if (isWindow(source) || isScope(source)) {
868 throw ngMinErr('cpws',
869 "Can't copy! Making copies of Window or Scope instances is not supported.");
870 }
871 if (isTypedArray(destination)) {
872 throw ngMinErr('cpta',
873 "Can't copy! TypedArray destination cannot be mutated.");
874 }
875
876 if (!destination) {
877 destination = source;
878 if (isObject(source)) {
879 var index;
880 if (stackSource && (index = stackSource.indexOf(source)) !== -1) {
881 return stackDest[index];
882 }
883
884 // TypedArray, Date and RegExp have specific copy functionality and must be
885 // pushed onto the stack before returning.
886 // Array and other objects create the base object and recurse to copy child
887 // objects. The array/object will be pushed onto the stack when recursed.
888 if (isArray(source)) {
889 return copy(source, [], stackSource, stackDest);
890 } else if (isTypedArray(source)) {
891 destination = new source.constructor(source);
892 } else if (isDate(source)) {
893 destination = new Date(source.getTime());
894 } else if (isRegExp(source)) {
895 destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
896 destination.lastIndex = source.lastIndex;
897 } else if (isFunction(source.cloneNode)) {
898 destination = source.cloneNode(true);
899 } else {
900 var emptyObject = Object.create(getPrototypeOf(source));
901 return copy(source, emptyObject, stackSource, stackDest);
902 }
903
904 if (stackDest) {
905 stackSource.push(source);
906 stackDest.push(destination);
907 }
908 }
909 } else {
910 if (source === destination) throw ngMinErr('cpi',
911 "Can't copy! Source and destination are identical.");
912
913 stackSource = stackSource || [];
914 stackDest = stackDest || [];
915
916 if (isObject(source)) {
917 stackSource.push(source);
918 stackDest.push(destination);
919 }
920
921 var result, key;
922 if (isArray(source)) {
923 destination.length = 0;

Callers 5

ReplyPXEFunction · 0.85
angular.jsFile · 0.85
$RootScopeProviderFunction · 0.85
ngModelOptionsDirectiveFunction · 0.85
resourceFactoryFunction · 0.85

Calls 10

isWindowFunction · 0.85
isScopeFunction · 0.85
isTypedArrayFunction · 0.85
isObjectFunction · 0.85
isDateFunction · 0.85
isRegExpFunction · 0.85
isFunctionFunction · 0.85
forEachFunction · 0.85
isBlankObjectFunction · 0.85
setHashKeyFunction · 0.85

Tested by

no test coverage detected