1. 程式人生 > >1009日重點: 深復制

1009日重點: 深復制

component replace ans one 復制 lac copy new pro

//深復制 var deepCopy= function(source) { var result={}; for (var key in source) { result[key] = typeof source[key]===‘object‘? deepCopy(source[key]): source[key]; } return result; }
function serializeData( data ) { // If this is not an object, defer to native stringification. if ( ! angular.isObject( data ) ) { return( ( data == null ) ? "" : data.toString() ); } var buffer = []; // Serialize each key in the object. for ( var name in data ) { if ( ! data.hasOwnProperty( name ) ) { continue; } var value = data[ name ]; buffer.push( encodeURIComponent( name ) + "=" + encodeURIComponent( ( value == null ) ? "" : value ) ); } // Serialize the buffer and clean it up for transportation. var source = buffer.join( "&" ).replace( /%20/g, "+" ); return( source ); }; 引用: $scope.newrow = deepCopy(data);

1009日重點: 深復制