In other words, in a like assignment to a variable, then the variable is still the point is like the original address. That the answer is how to do this cloning.
What is a "clone"?
Therefore, I deliberately wrote the two cloning methods: a shallow copy, a deep copy.
Shallow copy (shadow clone): just like to copy the basic types, like type, is still in the original quote.
Deep copy (deep clone): copy does not bear the basic categories of objects, but also copy the original object like. That is entirely generated by the new object.
The following is a code, I already tested, and have not had any problems, hope that we are interested to participate.
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN">
<TITLE> New Document </ TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META NAME="Generator" CONTENT="Wawa Editor 1.0">
<META NAME="Author" CONTENT="">
<META NAME="Description" CONTENT=",">
function Object.prototype.clone () (
var newObj = new Object ();
for (elements in this) (
newObj [elements] = this [elements];
function Object.prototype.cloneAll () (
function clonePrototype () ()
clonePrototype.prototype = this;
var obj = new clonePrototype ();
for (var ele in obj) (
if (typeof (obj [ele ])==" object ") obj [ele] = obj [ele]. cloneAll ();
var obj1 = new Object ();
obj1.Team = "First";
obj1.Powers = new Array ( "Iori", "Kyo");
obj1.msg = function () (alert ());
obj1.winner = new Object ();
obj1.winner.name = obj1.Powers ;
obj1.winner.age = 23;
obj1.winner.from = "Japan"
var obj1_clone = obj1.cloneAll ();
obj1_clone.Team = "Second";
obj1_clone.Powers = new Array ( "Jimmy", "Anndy");
obj1_clone.winner.name = obj1_clone.Powers ;
obj1_clone.winner.age = 22;
obj1_clone.winner.from = "USA";
msg = "2003 The King of Fighters on their own profession Cup Challenge The King of Fighters: \ n \ n A group against the form of: \ n \ n"
msg + = obj1.Team + "group list:" + obj1.Powers + "\ n";
msg + = "after the first round, the winner for:" + obj1.winner.name + ", No age:" + obj1.winner.age + ", from the island:" + obj1.winner.from + "\ n ";
msg + = "\ n \ n B team against the form of: \ n \ n"
msg + = obj1_clone.Team + "group list:" + obj1_clone.Powers + "\ n";
msg + = "after the first round, the winner for:" + obj1_clone.winner.name + ", No age:" + obj1_clone.winner.age + ", from the international police force:" + obj1_clone.winner.from + " \ n ";
Java skills and code Articles
- [Java] examples of the basic learning
- Study Notes
- Right java pop-up menu
- Java design patterns using UML to prepare examples of FactoryMethod Pattern
- Installation, upgrade, and uninstall the central part (java in preparation)
- To encapsulate the database operations Javabean
- JAVA dynamic compilation and static compilation
- java simple application of io
- Written in cipher with the Java classes
- The preparation of mine clearance with Java games - code for Thought
- Application of a simple timer: VarTimer (java)
- java feelings along the way
- java class in the use of Properties
- JAVA + ACCESS programming experience
- Getting Started javaRMI procedures and configuration
- On the development of JAVA VM
- How Java is rapidly becoming a master
Can't Find What You're Looking For?
Rating: Not yet rated