MCPcopy Create free account
hub / github.com/apache/cloudstack / copy

Function copy

tools/ngui/static/js/lib/angular.js:575–607  ·  view source on GitHub ↗

* @ngdoc function * @name angular.copy * @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 elements (for array) or pr

(source, destination)

Source from the content-addressed store, hash-verified

573 * @returns {*} The copy or updated `destination`, if `destination` was specified.
574 */
575function copy(source, destination){
576 if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope");
577 if (!destination) {
578 destination = source;
579 if (source) {
580 if (isArray(source)) {
581 destination = copy(source, []);
582 } else if (isDate(source)) {
583 destination = new Date(source.getTime());
584 } else if (isObject(source)) {
585 destination = copy(source, {});
586 }
587 }
588 } else {
589 if (source === destination) throw Error("Can't copy equivalent objects or arrays");
590 if (isArray(source)) {
591 destination.length = 0;
592 for ( var i = 0; i < source.length; i++) {
593 destination.push(copy(source[i]));
594 }
595 } else {
596 var h = destination.$$hashKey;
597 forEach(destination, function(value, key){
598 delete destination[key];
599 });
600 for ( var key in source) {
601 destination[key] = copy(source[key]);
602 }
603 setHashKey(destination,h);
604 }
605 }
606 return destination;
607}
608
609/**
610 * Create a shallow copy of an object

Callers 6

updateRouteFunction · 0.70
$RootScopeProviderFunction · 0.70
sendReqFunction · 0.70
formDirectiveFactoryFunction · 0.70
ngClassWatchActionFunction · 0.70
MultipleFunction · 0.70

Calls 9

isWindowFunction · 0.85
isScopeFunction · 0.85
isArrayFunction · 0.85
isDateFunction · 0.85
isObjectFunction · 0.85
forEachFunction · 0.85
setHashKeyFunction · 0.85
ErrorFunction · 0.50
getTimeMethod · 0.45

Tested by

no test coverage detected