_javascript techniques for the reciprocal referencing of variables in JavaScript

Source: Internet
Author: User

The test is as follows:

Array type testObject Type TestInstantiating a function testfunction parameter pass test by address
<textarea class="my_show_textarea" id="my_show_textarea">var a=b=[1,2]; A.push (3); Alert (a.length+ ': ' +b.length); </textarea>

About the impact on node object operations:

Since the function is passed by value, the node is referenced by the node itself rather than one of its clones when the node is inserted, so the nodes are shifted

Such as:

<textarea id="runcode56586"><! 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> <div class= "C1" id= "Div1" >div1</div> <div class= "C2" id= "Div2" ">div2</div> <input type=" button "value=" Append Div1 to Div2 "id=" button "/> <script" type= Ascript "> function $ (elem) {return document.getElementById (elem);} var div1=$ ("Div1"); var div2=$ ("Div2"); var button=$ ("button"); Button.onclick=function () {div2.appendchild (DIV1); }; </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The last one is about the removal of the node, originally thought to use innerhtml= "" To remove element content, in IE will be created in the node from memory completely eliminated, the fact is not so, but produced a very strange phenomenon:

Such as:
<! 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:" Microsoft Ya-hei "," 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> back and forth repeatedly click Add_div and inner to try, will find strange phenomenon. Click Alert and you will find that the div you created is not purged from memory. Using the RemoveChild method will be very normal performance </p> <div id= "div2" class= "C2" ></div> <input type= "button" value= "Add_div" /> <input type= "button" value= "inner"/> <input type= "button" value= "Remove"/> <input type= "button" value= "alert"/> <script type= "Text/javascript"> if (!+" \v1 ") {}else alert (" Please test in IE "); var elem=document.createelement ("div"); Elem.classname= "C1"; Elem.innerhtml= "Creatediv C1"; var elem2=document.createelement ("div"); Elem2.classname= "C3"; Elem2.innerhtml= "Creatediv C3"; Elem.appendchild (ELEM2); var Div2=document.getelementbyid ("Div2"); var inputs=document.getelementsbytagname ("input"); Inputs[0].onclick=function () {div2.appendchild (elem);}; Inputs[1].onclick=function () {div2.innerhtml= ""}; Inputs[2].onclick=function () {Div2.removechild (elem)}; Inputs[3].onclick=function () {alert (ELEM+ELEM2)}; </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.