MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / copy

Function copy

code/songhop/www/lib/angular/angular.js:764–835  ·  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

762 </example>
763 */
764function copy(source, destination, stackSource, stackDest) {
765 if (isWindow(source) || isScope(source)) {
766 throw ngMinErr('cpws',
767 "Can't copy! Making copies of Window or Scope instances is not supported.");
768 }
769
770 if (!destination) {
771 destination = source;
772 if (source) {
773 if (isArray(source)) {
774 destination = copy(source, [], stackSource, stackDest);
775 } else if (isDate(source)) {
776 destination = new Date(source.getTime());
777 } else if (isRegExp(source)) {
778 destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
779 destination.lastIndex = source.lastIndex;
780 } else if (isObject(source)) {
781 var emptyObject = Object.create(Object.getPrototypeOf(source));
782 destination = copy(source, emptyObject, stackSource, stackDest);
783 }
784 }
785 } else {
786 if (source === destination) throw ngMinErr('cpi',
787 "Can't copy! Source and destination are identical.");
788
789 stackSource = stackSource || [];
790 stackDest = stackDest || [];
791
792 if (isObject(source)) {
793 var index = stackSource.indexOf(source);
794 if (index !== -1) return stackDest[index];
795
796 stackSource.push(source);
797 stackDest.push(destination);
798 }
799
800 var result;
801 if (isArray(source)) {
802 destination.length = 0;
803 for (var i = 0; i < source.length; i++) {
804 result = copy(source[i], null, stackSource, stackDest);
805 if (isObject(source[i])) {
806 stackSource.push(source[i]);
807 stackDest.push(result);
808 }
809 destination.push(result);
810 }
811 } else {
812 var h = destination.$$hashKey;
813 if (isArray(destination)) {
814 destination.length = 0;
815 } else {
816 forEach(destination, function(value, key) {
817 delete destination[key];
818 });
819 }
820 for (var key in source) {
821 if (source.hasOwnProperty(key)) {

Callers 4

angular.jsFile · 0.70
$RootScopeProviderFunction · 0.70
$getFunction · 0.50
$getFunction · 0.50

Calls 7

isWindowFunction · 0.70
isScopeFunction · 0.70
isDateFunction · 0.70
isRegExpFunction · 0.70
isObjectFunction · 0.70
forEachFunction · 0.70
setHashKeyFunction · 0.70

Tested by

no test coverage detected