JavaScript Replication Object Usage Description _js Object oriented

Source: Internet
Author: User
Tags closing tag
Oldobj is an object, not a value
For example Var newobj=oldobj;
If you want to oldobj change the time does not affect the newobj;
You can write a function like this
Copy Code code as follows:

function Clone (myobj) {
if (typeof (MyObj)!= ' object ') return myobj;
if (myobj = null) return myobj;
var mynewobj = new Object ();
for (var i in myobj)
Mynewobj[i] = Clone (Myobj[i]);
return mynewobj;
}

And then call this
Newobj=clone (Oldobj)
After that, no matter how the value of the oldobj changes, it will not affect newobj

JavaScript Replication Objects
Grammar:
Oelement = object. CloneNode (Bclonechildren)

Parameters:
Bclonechildren: Options available. A Boolean value (Boolean). False | True
False: Default value. The ChildNodes collection of object is not included when the object is cloned. That is, all its child objects.
True: Contains the ChildNodes collection of object when cloning object. That is, all its child objects.

return value:
Oelement: Object (Element). Returns a reference to the new object after the clone.
Description
Clones the object in the document structure.
When the clone gets the ID of the cloned object, a collection is returned.
It is possible to use this method at run time. The document space may not be rendered before the object's closing tag is parsed.
Sample code:
Copy Code code as follows:

<script>
Function Rdl_fnclone () {
var oclonenode=olist.clone Node (TRUE);
Clonearea.appendchild (Oclonenode);
}
</script>
<table width=98%><tr><td>
<ul id=olist>
<li> 1th List Items
<li> 2nd <a href= "#" onclick= "return false;" > list Items </a>
<li style= "font-weight:bold;" > 3rd list Items
</ul>
</td><td id=clonearea>
</td></tr></table>
& L T;input Type=button value= "cloning" onclick= "Rdl_fnclone ();" >
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.