for the singleton mode in Javascript, the benefits of Singleton mode will not be introduced, but the singleton Writing of JavaScript is just written!
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> JS Singleton mode </title> <br/> <style type =" text/CSS "> <br/> Div {height: 100px; width: 100px; Background: # CCC; Border: #000 1px solid;} <br/> </Style> <Br/> <SCRIPT type = "text/JavaScript"> <br/> my = new function yangbin () {<br/> This. name = "I'm a singleton funnyzak! "; <Br/>}; </P> <p> function yangbin1 () {<br/> This. Name =" I am funnyzak! "; <Br/>}< br/> function myname () {<br/> var u = new yangbin1 (); <br/> alert (U. name ); <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body> <br/> <Div onclick = "alert (my. name); "> you are? (Singleton) </div> <br/> <Div onclick = "myname ();"> are you? (Normal) </div> <br/> </body> <br/> </ptml> <br/>
RunCode