Mutual reference of variables in JavaScript

Source: Internet
Author: User

The test is as follows:

Array type test Object Type Test Test the instantiation function. Test the function parameter passing by address
Var a = B = [1, 2]; a. push (3); alert (a. length + ':' + B. length );

Impact on Node object operations:

Because the function is passed by value, when a node is inserted, the node itself is referenced, rather than its clone. Therefore, the node is transferred.

For example:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = gb2312 "/> <title> untitled document </title> <style type =" text/css ">. c2 {border: 1px solid # ccc; width: 100px; height: 100px ;}. c1 {border: 2px solid #000; width: 50px; height: 60px ;} </style> </pead> <body> div1 div2 <input type = "button" value = "append div1 to div2" id = "button"/> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The last one is about removing the node. If we thought we would use innerHTML = "" to remove the element content, we will completely remove the created node from the memory in IE. This is not the case, however, a strange phenomenon occurs:

For example:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = gb2312 "/> <title> untitled document </title> <style type =" text/css "> body {font-family:" ", "Times New Roman", Times, serif; font-size: 12px ;}. c2 {border: 1px solid # ccc; width: 500px ; Height: 150px ;}. c1 {border: 2px solid #000; width: 300px; height: 100px ;}. c3 {border: 1px solid # ccc; width: 100px; height: 50px ;}</style> </pead> <body> <p> click add_div and inner again and again, it will find a strange phenomenon. Click alert and the created div is not cleared from the memory. The removeChild method works normally. </p> <input type = "button" value = "add_div"/> <input type = "button" value = "inner"/> <input type = "button" value = "remove"/> <input type = "button" value = "alert"/> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.