<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1845163993653853397</id><updated>2024-09-05T01:48:32.656+02:00</updated><category term="javascript"/><category term="gwt"/><category term="Ubuntu"/><category term="linux"/><category term="gwt 2.0"/><category term="php"/><category term="ubuntu  11.04"/><category term="ubuntu 11.04"/><category term="Ubuntu 9.10"/><category term="desktop"/><category term="eclipse"/><category term="plugin"/><category term="skype"/><category term="unity"/><category term="widget"/><category term="wireless"/><category term="wlan"/><category term="NetBeans"/><category term="Tomcat6"/><category term="ajax"/><category term="apache"/><category term="browser"/><category term="css"/><category term="dell vostro 3750"/><category term="espressioni regolari javascript"/><category term="firefox"/><category term="gears"/><category term="gnome"/><category term="grepolis"/><category term="gwt-gears"/><category term="hp1020"/><category term="hplib"/><category term="html"/><category term="js"/><category term="lamp"/><category term="laserjetfoo2js"/><category term="mysql"/><category term="network"/><category term="parseInt"/><category term="php.ini"/><category term="regular expression"/><category term="rfkill"/><category term="web developer tools"/><title type='text'>Gheryd</title><subtitle type='html'>cogito ergo boh :)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>40</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-2888096113250339006</id><published>2019-07-14T15:35:00.004+02:00</published><updated>2019-07-14T15:35:50.319+02:00</updated><title type='text'>javascript ES6 ES2015</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
const&lt;/h2&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;const myVar = &#39;value&#39;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;myVar = &#39;value2&#39;;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;// error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
let&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;var myVar = &#39;value&#39;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;if( myVar ){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; let myVar = &#39;value2&#39;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; console.log(myVar);&amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;// &#39;value2&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #999999; font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;console.log(myVar);&amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;// &#39;value&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
String Template&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myHtml = `&amp;lt;div&amp;gt;&lt;span style=&quot;color: red;&quot;&gt;${myVar}&lt;/span&gt;&amp;lt;/div&amp;gt;`; &lt;span style=&quot;color: #999999;&quot;&gt;// ` -&amp;gt; back tick character&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myTemplate = `&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;span&amp;gt;&lt;span style=&quot;color: red;&quot;&gt;${var1}&lt;/span&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;span&amp;gt;&lt;span style=&quot;color: red;&quot;&gt;${var2}&lt;/span&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;`;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Default values&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;function myFunction(par=&#39;some value&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;// code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;var defaultValue = &#39;value&#39;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;function MyFunction2(par=defaultValue){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;// code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Arrow function&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let add5 = par1 =&amp;gt; par1+5;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let sum = (par1, par2) =&amp;gt; par1 + par2;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myFunc = (par1, par2) =&amp;gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; if(par1&amp;lt;=0){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; par1 = 1;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;return par1*par2;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myObj = {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; myMeth: function(){&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;// code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;myMeth2: function(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;setTimeout(function(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.myMeth(); &lt;span style=&quot;color: #999999;&quot;&gt;// ERROR! function not preserve scope&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }, 1000);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;myMeth2: function(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setTimeout( ()=&amp;gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.myMeth();&amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;// scope is myObj&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },1000);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Destructuring&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj = {k1:v1, k2: v2};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let {k1, k2} = obj;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;console.log(k1, k2);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myFunc = ({k1}) =&amp;gt; console.log(k1);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let arr = [&#39;first&#39;, &#39;second&#39;, &#39;third&#39;];&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let [firstItem] = arr;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let [,, thirdItem] = arr;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Object Literal Ehancement&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let var1 = value1;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let var2 = value2;//rest is array without first item&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj = {var1, var2}; &lt;span style=&quot;color: #999999;&quot;&gt;//obj= {var1:value1, var2:value2}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let myFunc = function(){&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return this.var1;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj2 =&amp;nbsp; {var1, var2, myFunc};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj3 = {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; prop1,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; prop2,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; myMeth(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;//code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Spread Operator&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let arr1 = [v1, v2, v3];&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let arr2 = [v4, v5, v6];&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let arr3 = [...arr1, ...arr2]; &lt;span style=&quot;color: #999999;&quot;&gt;//arr3 = [v1, v2, v3, v4, v5, v6];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let [last] = arr.reverse(); &lt;span style=&quot;color: #999999;&quot;&gt;//array altered&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let [last] = [...arr].reverse();&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let [first, ...rest] = arr; &lt;span style=&quot;color: #999999;&quot;&gt;//rest is array without first item&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj = {k1:v1, k2:v2};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let prop = value;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let obj2 = {...obj, prop};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Promise&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;const getUsers = count =&amp;gt; new Promise(&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (resolves, rejects) =&amp;gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const url = `http://myapi/user/?limit:${count}`;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const req = new XMLHttpRequest/(;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;req.open(&#39;GET&#39;, url);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;req.onload = () =&amp;gt;&amp;nbsp; req,status == 200 ?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resolves(JSON.parse(req.response)).results :&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reject(Error(req.statusText));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;req.onerror = (err) =&amp;gt; reject(err);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;req.send();&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;getUsers(10).then(&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;users=&amp;gt;console.log(users),&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;err =&amp;gt; console.error(err)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;getUsers(10)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; .then(users=&amp;gt;console.log(users))&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; .catch(err=&amp;gt;console.log(err));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Class&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class MyClass {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; constructor(par1, par2){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;// code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; myMeth(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;// code&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class MyClass2 extends MyClass{&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; constructor(par1, par2, par3){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super(par1, par2);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;// code&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; myMeth2(){&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;// code&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Module&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Module -&amp;gt; file&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;file1.js&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;export const myFunc = (par1) =&amp;gt; par1+5;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;export const myFunc2 = (par2) =&amp;gt; par2^2;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;file2,js&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;export const default myVar = 5;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;file3.js&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;import {myFunc, myFunct2} from &quot;./file1&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;import {myVar} from &quot;./file2&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;alias&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;import {myFunc as f1, myFunct2 as f2} from &quot;./file1&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;all&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;import * as f from &quot;./file1&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;u&gt;NodeJS (Common js)&lt;/u&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;file1.js&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;module.exports = {myFunc, myFunct2};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;file3.js&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;const {myFunc, MyFunc2} = require(&quot;./file1&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/2888096113250339006/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2019/07/javascript-es6-es2015.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/2888096113250339006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/2888096113250339006'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2019/07/javascript-es6-es2015.html' title='javascript ES6 ES2015'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-398596981903401171</id><published>2018-08-03T13:58:00.000+02:00</published><updated>2018-08-05T20:52:47.664+02:00</updated><title type='text'>React prefill input/form</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;p&gt;In these example form components are &lt;u&gt;react uncontrolled components&lt;/u&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s best practice using controlled input (value+onChange. https://reactjs.org/docs/forms.html)&lt;/p&gt;
&lt;hr/&gt;
Example 1: implement &lt;b&gt;componentDidUpdate&lt;/b&gt; method 
&lt;/p&gt;
&lt;code&gt;
&lt;xmp&gt;
class Form extends Component {

    submit = (e) =&gt; {
        e.preventDefault();
        var user = Object.keys(this.refs).reduce( (obj, k) =&gt;{
            obj[k] = this.refs[k].value;
            this.refs[k].value = &#39;&#39;;
            return obj;
        }, {} );
        this.props.onSubmit(user);
    }

    onChange = ({target:el}) =&gt; el.value = el.value.toUpperCase();

    render() {
        return (
        &lt;form onSubmit={this.submit}&gt;
            &lt;div className=&quot;form-group&quot;&gt;
                &lt;input type=&quot;text&quot; 
                       ref=&quot;name&quot;
                       className=&quot;form-control&quot; 
                       placeholder = &quot;name&quot;/&gt;
            &lt;/div&gt;
            &lt;div className=&quot;form-group&quot;&gt;
                &lt;input type=&quot;text&quot; 
                       ref=&quot;surname&quot; 
                       onChange={this.onChange} 
                       className=&quot;form-control&quot; 
                       placeholder=&quot;surname&quot; /&gt;
            &lt;/div&gt;
            &lt;button type=&quot;submit&quot; className=&quot;btn btn-primary&quot;&gt;add&lt;/button&gt;
        &lt;/form&gt;
        );
    }

    componentDidUpdate(){
        const {user} = this.props; 
        this.refs.name.value = user.name;
        this.refs.surname.value = user.surname; 
    }
}

&lt;/xmp&gt;
&lt;/code&gt;
&lt;hr/&gt;
&lt;p&gt;Example 2: use &lt;b&gt;defaultValue&lt;/b&gt;&lt;/p&gt;
&lt;code&gt;
&lt;xmp&gt;
class Content6 extends Component {
    state = { 
        formCfg: {name:&#39;&#39;, cities:[]},
        submittedData: {}
     }

    dataList = [
        {name:&#39;Pippo&#39;, cities:[&#39;Milan&#39;, &#39;Rome&#39;, &#39;Palermo&#39;], isMale:true, defaultCity:&#39;Rome&#39; },
        {name:&#39;Tina&#39;, cities:[&#39;Torino&#39;, &#39;Genova&#39;, &#39;Pavia&#39;], isMale:false},
        {name:&#39;Pino&#39;, cities:[&#39;Venice&#39;, &#39;Padova&#39;, &#39;Firenze&#39;], isMale:true}
    ]

    onClick = (formCfg) =&gt; this.setState({formCfg}); 
    onSave = (submittedData) =&gt; this.setState({submittedData});
    render() {
        const {formCfg, submittedData} = this.state; 
        return ( &lt;div&gt;
            &lt;p&gt;click item to fill form:&lt;/p&gt;
            {this.dataList.map( (cfg, i)=&gt;(
            &lt;div key={i} onClick={(ev)=&gt;this.onClick(cfg)} 
                style={{cursor:&#39;pointer&#39;, backgroundColor:&#39;#CCC&#39;, margin:2}}&gt;
                {JSON.stringify(cfg)}
            &lt;/div&gt;))}
            &lt;div&gt;
                &lt;p&gt;Submitted data: {JSON.stringify(submittedData)}&lt;/p&gt;
            &lt;/div&gt;
            &lt;div&gt;&lt;FormSL {...formCfg} save={this.onSave}/&gt;&lt;/div&gt;

        &lt;/div&gt; );
    }
}

//stateless component
class FormSL extends Component {

    onSubmit = ({name: {value:name}, city:{value:city},isMale:{checked:isMale}}) =&gt; 
                   this.props.save({name, city, isMale});

    render() { 
        const {name, cities,isMale, defaultCity} = this.props;
        return ( &lt;form&gt;
            &lt;input ref=&#39;name&#39; defaultValue={name} type=&quot;text&quot; className=&quot;form-control&quot; /&gt;&lt;br/&gt;
            &lt;select ref=&#39;city&#39; name=&quot;&quot; id=&quot;&quot; className=&quot;form-control&quot; size={cities.length+1}&gt;
                &lt;option value=&#39;&#39;&gt;[select city]&lt;/option&gt;
                {cities.map((city)=&gt;&lt;option 
                    key={city} 
                    value={city.toUpperCase()} 
                    selected={defaultCity===city}&gt;
                    {city}
                &lt;/option&gt; ) }
            &lt;/select&gt;&lt;br/&gt;
            &lt;input ref=&quot;isMale&quot; type=&quot;checkbox&quot; defaultChecked={isMale} /&gt; isMale&lt;br/&gt;
            &lt;button type=&quot;button&quot; onClick={() =&gt; this.onSubmit(this.refs)} &gt;submit&lt;/button&gt;
        &lt;/form&gt; );
    }
}



&lt;/xmp&gt;
&lt;/code&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/398596981903401171/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2018/08/react-prefill-input.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/398596981903401171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/398596981903401171'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2018/08/react-prefill-input.html' title='React prefill input/form'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-2727486959362508848</id><published>2015-02-03T10:33:00.001+01:00</published><updated>2015-02-03T10:33:45.859+01:00</updated><title type='text'>PHP | JS: convert date format to sql timestamp</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;HTML&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;&lt;b&gt;input&lt;/b&gt; id=&quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;myinput&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot; type=&quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot; value=&quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;20/09/1973&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot; /&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&lt;i&gt;&amp;lt;!-- format: dd/mm/yyyy --&amp;gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Javascript&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;var&lt;/b&gt; mydate =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;document&lt;/b&gt;.&lt;b&gt;getElementById&lt;/b&gt;(&quot;myinput&quot;).value;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;var&lt;/b&gt; t =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;mydate&lt;/span&gt;&lt;span style=&quot;color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;.&lt;b&gt;replace&lt;/b&gt;(&lt;/span&gt;&lt;span style=&quot;color: purple; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;/^(\d{2})\/(\d{2})\/(\d{4})$/&lt;/span&gt;&lt;span style=&quot;color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;, &quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;$3-$2-$1 00:00:00&lt;/span&gt;&lt;span style=&quot;color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;i&gt;//t= &quot;1973-09-20 00:00:00&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;b&gt;PHP&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;echo&lt;/b&gt; &lt;i&gt;preg_replace&lt;/i&gt;(&quot;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;/^(\d{2})\/(\d{2})\/(\d{4})$/&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;$3-$2-$1 00:00:00&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;20/09/1973&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/2727486959362508848/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2015/02/php-js-convert-date-format-to-sql.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/2727486959362508848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/2727486959362508848'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2015/02/php-js-convert-date-format-to-sql.html' title='PHP | JS: convert date format to sql timestamp'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-3893477657503313699</id><published>2014-12-03T13:16:00.000+01:00</published><updated>2014-12-03T13:21:51.042+01:00</updated><title type='text'>angular js: set input focus</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;var app = angular&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.module(&quot;app&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;i&gt;factory&lt;/i&gt;(&quot;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;mySetFocus&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&quot;, [&quot;$timeout&quot;, function($timeout){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;focus : {},&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;set : function(name){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;this.focus[name] = !!!this.focus[name];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.&lt;i&gt;directive&lt;/i&gt;(&#39;&lt;span style=&quot;color: red;&quot;&gt;myFocus&lt;/span&gt;&#39;, [&quot;$timeout&quot;, &quot;mySetFocus&quot;, function($timeout, mySetFocus) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;restrict: &#39;A&#39;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;link : function(scope, element, attrs) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;scope.setter = mySetFocus;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;scope.$watch(&quot;setter.focus.&quot;+attrs.name, function(v){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;            &lt;/span&gt;if(v==undefined) return;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;            &lt;/span&gt;$timeout(function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;               &lt;/span&gt;element[0].focus();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;            &lt;/span&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.&lt;i&gt;controller&lt;/i&gt;(&quot;myCtrl&quot;, [&quot;$scope&quot;, &quot;mySetFocus&quot;, function($scope, mySetFocus){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;mySetFocus&lt;/span&gt;.set(&quot;&lt;span style=&quot;color: #6aa84f;&quot;&gt;myfield&lt;/span&gt;&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}]);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: large;&quot;&gt;&amp;lt;form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: large;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;&amp;lt;input name=&quot;&lt;span style=&quot;color: #93c47d;&quot;&gt;myfield&lt;/span&gt;&quot; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;my-focus&lt;/span&gt;&lt;/b&gt; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: large;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/3893477657503313699/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2014/12/angular-js-set-input-focus.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/3893477657503313699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/3893477657503313699'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2014/12/angular-js-set-input-focus.html' title='angular js: set input focus'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-1899184670614030960</id><published>2014-05-17T19:45:00.000+02:00</published><updated>2014-05-17T19:51:55.622+02:00</updated><title type='text'>AngularJs: creare una tabella con riodinamenti crescenti e decrescenti via template</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Nel template html seguente, viene creata una tabella tramite AngularJs in cui le colonne sono riordinabli con un click sull&#39;header della colonna.&lt;br /&gt;
Questo viene fatto tramite una semplice condizione&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: inherit;&quot;&gt;ng-click = &quot;colOrd= colOrd==&#39;fieldname&#39; &amp;amp;&amp;amp; &#39;-fieldame&#39; || &#39;fieldname&#39;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
che assegna al parametro &quot;colOrd&quot; utilizzato per il filtro &quot;orderBy&quot;, il nome del campo preceduto dal segno meno (ordinamento decrescente) se gia è attivo l&#39;ordinamento crescente su questa colonna.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;span&amp;gt;ordinamento attuale: {{colOrd}}&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;table border=1 cellpadding=5&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;lt;tr&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td ng-click=&quot;&lt;span style=&quot;background-color: yellow;&quot;&gt;colOrd= colOrd==&#39;id&#39; &amp;amp;&amp;amp; &#39;-id&#39; || &#39;id&#39;&lt;/span&gt;&quot;&amp;gt;Id:&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td ng-click=&quot;&lt;span style=&quot;background-color: yellow;&quot;&gt;colOrd= colOrd==&#39;nome&#39; &amp;amp;&amp;amp; &#39;-nome&#39; || &#39;nome&lt;/span&gt;&#39;&quot;&amp;gt;Nome:&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td ng-click=&quot;&lt;span style=&quot;background-color: yellow;&quot;&gt;colOrd= colOrd==&#39;cognome&#39; &amp;amp;&amp;amp; &#39;-cognome&#39; || &#39;cognome&#39;&lt;/span&gt;&quot;&amp;gt;Cognome:&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td ng-click=&quot;&lt;span style=&quot;background-color: yellow;&quot;&gt;colOrd= colOrd==&#39;cell&#39; &amp;amp;&amp;amp; &#39;-cell&#39; || &#39;cell&#39;&lt;/span&gt; &quot;&amp;gt;Cellulare:&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;lt;tr ng-repeat=&quot;item in mylist |&amp;nbsp;&lt;span style=&quot;background-color: yellow; color: #e06666;&quot;&gt;orderBy:colOrd&lt;/span&gt;&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;{{item.id}}&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;{{item.nome}}&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;{{item.cognome}}&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;{{item.cell}}&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/1899184670614030960/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2014/05/angularjs-creare-una-tabella-con.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1899184670614030960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1899184670614030960'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2014/05/angularjs-creare-una-tabella-con.html' title='AngularJs: creare una tabella con riodinamenti crescenti e decrescenti via template'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-6714546647541287752</id><published>2013-11-09T20:43:00.004+01:00</published><updated>2013-11-11T18:17:50.251+01:00</updated><title type='text'>dojo autocomplete (suggest box)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: small;&quot;&gt;CLIENT&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: small;&quot;&gt;(html)&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: #c27ba0; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;input id=&quot;mySuggestBox&quot; /&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: small;&quot;&gt;(javascript dojo v.1.9):&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: red; font-family: Courier New, Courier, monospace;&quot;&gt;require([&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &quot;dojo/_base/declare&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot;dojox/data/QueryReadStore&quot;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot;dijit/form/ComboBox&quot;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot;dojo/domReady!&quot;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;], function(declare, QueryReadStore, ComboBox) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;var &lt;b&gt;AutocompleteStore &lt;/b&gt;= declare(QueryReadStore, {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; fetch: function(request){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; request.serverQuery = {q:request.query.name};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return this.inherited(&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc; font-family: Courier New, Courier, monospace;&quot;&gt;&quot;fetch&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;, arguments);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; wrapItem: function(rawItem, callback){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this._xhrFetchHandler({&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; identifier:&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&#39;id&#39;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; items: [rawItem],&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; label: &lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&#39;label&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {},&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; function(items){&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; callback(items[0]);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;var &lt;b&gt;store &lt;/b&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;new &lt;b&gt;AutocompleteStore&lt;/b&gt;({url:&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&#39;services/myservice.php&#39;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;});&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;var &lt;b&gt;cb &lt;/b&gt;= new &lt;b&gt;ComboBox&lt;/b&gt;({&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; store: &lt;b&gt;store&lt;/b&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; searchAttr: &lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; labelAttr: &lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;label&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; autoComplete: true,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; onChange: function(){ &amp;nbsp;if(!&lt;b&gt;this&lt;/b&gt;.item) &amp;nbsp;&lt;b&gt;this&lt;/b&gt;.set(&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;displayedValue&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;, &quot;&quot;); &amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; }, &lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;mySuggestBox&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&amp;nbsp; &lt;span style=&quot;color: #cccccc;&quot;&gt;//set default value&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &lt;b&gt;store&lt;/b&gt;.&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;wrapItem&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;({id:111, name:&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;lorem&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;, label: &lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;ipsum&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;}, function(item){&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;cb&lt;/b&gt;.set(&lt;/span&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;, item);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #990000; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: small;&quot;&gt;SERVER&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: small;&quot;&gt;(myservice.php):&lt;/span&gt;&lt;/h3&gt;
&lt;b&gt;&lt;span style=&quot;color: red; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #93c47d; font-family: Courier New, Courier, monospace;&quot;&gt;$q = $_GET[&quot;q&quot;];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #93c47d;&quot;&gt;$sql = &quot;SELECT field_id AS id, field_xxx AS name, CONCACT(&#39;&amp;lt;b&amp;gt;&#39;,field_xxx,&#39;&amp;lt;/b&#39;)&quot; AS label FROM myTable WHERE&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #93c47d;&quot;&gt;field_xxx&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #93c47d;&quot;&gt;LIKE &quot;%{$q}% ORDER BY field_xxx LIMIT 10&quot;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;//fetch query... :&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;/*&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;$fields = array(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&amp;nbsp; &amp;nbsp; array (id=&amp;gt;1, name=&amp;gt;&quot;lorem&quot;, label&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&amp;nbsp;&quot;&amp;lt;span&amp;gt;lorem&amp;lt;/span&amp;gt;&quot;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&amp;nbsp; &amp;nbsp; array (id=&amp;gt;2, name&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&quot;ipsum&quot;, label&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&quot;&amp;lt;span&amp;gt;impsum&amp;lt;/span&amp;gt;&quot;,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cccccc; font-family: Courier New, Courier, monospace;&quot;&gt;*/&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #93c47d; font-family: Courier New, Courier, monospace;&quot;&gt;header(&quot;Content-Type&quot;, &quot;text/json&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #93c47d; font-family: Courier New, Courier, monospace;&quot;&gt;echo json_encode(array(&#39;numRows&#39;=&amp;gt;count($fields), &#39;items&#39;=&amp;gt;$fields, &#39;identity&#39;=&amp;gt;&#39;id&#39;));&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/6714546647541287752/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2013/11/dojo-autocomplete-suggest-box.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/6714546647541287752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/6714546647541287752'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2013/11/dojo-autocomplete-suggest-box.html' title='dojo autocomplete (suggest box)'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-858418752535376208</id><published>2012-02-11T17:27:00.002+01:00</published><updated>2012-02-12T13:12:02.925+01:00</updated><title type='text'>GWT: SplitLayoutPanel, double(or single) click to show/hide panel</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;La classe seguente consente di chiudere o mostrare i pannelli di uno SplitLayoutPanel tramite un doppio click sugli &quot;splitters&quot; (le barre per ridimensionare i pannelli).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Il doppio click viene riconosciuto se l&#39;intervallo tra un click e quello successivo non supera un secondo (primo valore evidenziato in giallo espresso in millisecondi).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;L&#39;animazione che mostra o nasconde il pannello dura 500 millisecondi (secondo valore evidenziato in giallo).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public class&lt;/span&gt;&lt;/b&gt; SplitLayoutPanelExt &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;extends &lt;/span&gt;&lt;/b&gt;SplitLayoutPanel {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private class &lt;/span&gt;&lt;/b&gt;ClickSplitter {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private &lt;/span&gt;&lt;/b&gt;Widget &lt;span style=&quot;color: #3d85c6;&quot;&gt;widget&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private &lt;/span&gt;&lt;/b&gt;Widget &lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;long &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt; = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public &lt;/span&gt;&lt;/b&gt;ClickSplitter(Widget w, Widget splitter){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;.&lt;span style=&quot;color: #3d85c6;&quot;&gt;widget &lt;/span&gt;= w;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;.&lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter &lt;/span&gt;= splitter;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void &lt;/span&gt;&lt;/b&gt;onAttach(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;DOM.&lt;i&gt;setEventListener&lt;/i&gt;(&lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;.getElement(), &lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;new &lt;/b&gt;&lt;/span&gt;EventListener() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;public void &lt;/b&gt;&lt;/span&gt;onBrowserEvent(Event event) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;(Event.&lt;i&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;ONMOUSEDOWN&lt;/span&gt;&lt;/i&gt;==event.getTypeInt()){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;long &lt;/span&gt;&lt;/b&gt;t2 = (new Date()).getTime();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;(t2-&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt;&amp;gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;1000&lt;/span&gt;) { &lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt; = t2; &lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;.onBrowserEvent(event); &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;return&lt;/span&gt;&lt;/b&gt;; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;LayoutData layout = (LayoutData)&lt;span style=&quot;color: #3d85c6;&quot;&gt;widget&lt;/span&gt;.getLayoutData();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;(layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&lt;/span&gt;&amp;gt;0){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize &lt;/span&gt;= layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size &lt;/span&gt;= 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;else &lt;/span&gt;&lt;/b&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size &lt;/span&gt;= layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize&lt;/span&gt; = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt;=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;animate(&lt;span style=&quot;background-color: yellow;&quot;&gt;500&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;event.preventDefault();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;else &lt;/span&gt;&lt;/b&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;.onBrowserEvent(event);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private &lt;/span&gt;&lt;/b&gt;List&amp;lt;ClickSplitter&amp;gt; &lt;span style=&quot;color: #3d85c6;&quot;&gt;clickSplitterList &lt;/span&gt;= &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;ArrayList&amp;lt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; addWestClosable( Widget widget, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;double &lt;/span&gt;&lt;/b&gt;size) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;super&lt;/b&gt;&lt;/span&gt;.addWest(widget, size);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;add&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(widget);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; addEastClosable( Widget widget, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;double &lt;/span&gt;&lt;/b&gt;size){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;.addEast(widget, size);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(widget);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; addNorthClosable(Widget widget, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;double &lt;/span&gt;&lt;/b&gt;size){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;.addNorth(widget, size);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(widget);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; addSouthClosable(Widget widget, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;double &lt;/span&gt;&lt;/b&gt;size){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;.addSouth(widget, size);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(widget);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;private void&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ClickSplitter&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(Widget widget){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;int &lt;/span&gt;&lt;/b&gt;idx = super.getWidgetIndex(widget);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;(idx&amp;gt;-1 &amp;amp;&amp;amp; idx &amp;lt; getWidgetCount()-1){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Widget splitter = &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;.getWidget(idx+1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;clickSplitterList&lt;/span&gt;.add(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;ClickSplitter(widget, splitter));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;protected void&lt;/span&gt;&lt;/b&gt; onAttach() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;.onAttach();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;for&lt;/span&gt;&lt;/b&gt;(ClickSplitter clickSplitter: &lt;span style=&quot;color: #3d85c6;&quot;&gt;clickSplitterList&lt;/span&gt;){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  clickSplitter&lt;/span&gt;.onAttach();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Example:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * This is the entry point method.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; onModuleLoad() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;SplitLayoutPanelExt splitLayoutPanelExt = &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;SplitLayoutPanelExt();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addWestClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;west panel&quot;&lt;/span&gt;), 200);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addWestClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;west2 panel&quot;&lt;/span&gt;), 200);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addEastClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;east panel&quot;&lt;/span&gt;), 200);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addEastClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;east2 panel&quot;&lt;/span&gt;), 200);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addNorthClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;north panel&quot;&lt;/span&gt;), 100);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.addSouthClosable(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;south panel&quot;&lt;/span&gt;), 100);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;splitLayoutPanelExt.add(&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;new&lt;/b&gt; &lt;/span&gt;Label(&lt;span style=&quot;color: #3d85c6;&quot;&gt;&quot;center panel&quot;&lt;/span&gt;));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;RootLayoutPanel.&lt;i&gt;get&lt;/i&gt;().add(splitLayoutPanelExt);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Variante single click&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Per mostrare/nascondere i pannelli con un click singolo, sostituire il metodo &quot;onBrowserEvent&quot; con il seguente codice:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: Verdana, sans-serif;&quot;&gt;@Override&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;public void&amp;nbsp;&lt;/b&gt;&lt;/span&gt;onBrowserEvent(Event event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(Event.&lt;/span&gt;&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;ONMOUSEDOWN&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;==event.getTypeInt()){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt; = (new Date()).getTime();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;b style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;else if&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Event.&lt;/span&gt;&lt;i style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;ONMOUSEUP&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;==event.getTypeInt()&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;long&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;t2 = (new Date()).getTime();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;(t2-&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt;&amp;gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;200&lt;/span&gt;) {&amp;nbsp;&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt;&amp;nbsp;= 0;&amp;nbsp;&lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;.onBrowserEvent(event);&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;return&lt;/span&gt;&lt;/b&gt;; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;LayoutData layout = (LayoutData)&lt;span style=&quot;color: #3d85c6;&quot;&gt;widget&lt;/span&gt;.getLayoutData();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;(layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&lt;/span&gt;&amp;gt;0){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize&amp;nbsp;&lt;/span&gt;= layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&amp;nbsp;&lt;/span&gt;= 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;else&amp;nbsp;&lt;/span&gt;&lt;/b&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;size&amp;nbsp;&lt;/span&gt;= layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;layout.&lt;span style=&quot;color: #3d85c6;&quot;&gt;oldSize&lt;/span&gt;&amp;nbsp;= 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;t&lt;/span&gt;=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;animate(&lt;span style=&quot;background-color: yellow;&quot;&gt;500&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;splitter&lt;/span&gt;.onBrowserEvent(event);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/858418752535376208/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2012/02/public-class-splitlayoutpanelext.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/858418752535376208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/858418752535376208'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2012/02/public-class-splitlayoutpanelext.html' title='GWT: SplitLayoutPanel, double(or single) click to show/hide panel'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-7757148842648885951</id><published>2012-01-29T13:31:00.000+01:00</published><updated>2012-02-23T16:29:48.967+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="widget"/><title type='text'>GWT: eventi righe per FlexTable</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;La classe GWT seguente consente di aggiungere un handler per gli eventi di onclick, onmouseover e onmouseout per le righe di una flextable.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;import &lt;/span&gt;&lt;/b&gt;com.google.gwt.user.client.Element;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;import &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;com.google.gwt.user.client.DOM;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;import &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;com.google.gwt.user.client.Event;&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;com.google.gwt.user.client.EventListener;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; FlexTableExt &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;extends &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTable {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;b&gt;public static interface &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;RowEventsHandler {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; onClick(FlexTableExt&amp;nbsp;source,&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;int &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;public void&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;onMouseOver(FlexTableExt&amp;nbsp;source,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;int &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; onMouseOut(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;source,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #a64d79; font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;int &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt; &lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt; setRowEventsHandler(&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;final int &lt;/span&gt;&lt;/b&gt;row, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;final&amp;nbsp;
&lt;/span&gt;&lt;/b&gt;RowEventsHandler&amp;nbsp;&amp;nbsp;handler){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Element rowEl = &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;.getRowFormatter().getElement(row);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DOM.&lt;i&gt;setEventListener&lt;/i&gt;(rowEl, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;EventListener(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt; public void&lt;/b&gt;&lt;/span&gt; onBrowserEvent(Event event) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;switch&lt;/span&gt;&lt;/b&gt;(event.getTypeInt()){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;case&amp;nbsp;&lt;/span&gt;&lt;/b&gt;Event.&lt;i&gt;ONCLICK&lt;/i&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;handler.onClick(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt.&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row); &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;case &lt;/b&gt;&lt;/span&gt;Event.&lt;i&gt;ONMOUSEOVER&lt;/i&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;handler.onMouseOver(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt.&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row); &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;case&amp;nbsp;&lt;/b&gt;&lt;/span&gt;Event.&lt;i&gt;ONMOUSEOUT&lt;/i&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;handler.onMouseOut(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt.&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row); &lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;DOM.&lt;i&gt;sinkEvents&lt;/i&gt;(rowEl, Event.&lt;i&gt;ONCLICK &lt;/i&gt;| Event.&lt;i&gt;ONMOUSEOUT&lt;/i&gt; | Event.&lt;i&gt;ONMOUSEOVER&lt;/i&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;i&gt;Example:&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt ft = &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new &lt;/span&gt;&lt;/b&gt;FlextTableExt();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;RowEventsHandler rowHandler =&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;new&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;FlexTableExt.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;owEventsHandler(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&amp;nbsp;&lt;/span&gt;&lt;/b&gt;onClick(FlexTableExt&amp;nbsp;&amp;nbsp;ft, &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;int &lt;/span&gt;&lt;/b&gt;row){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Window.&lt;i&gt;alert&lt;/i&gt;(&lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;click row:&amp;nbsp;&lt;/span&gt;&quot;+row);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;public void&amp;nbsp;&lt;/b&gt;&lt;/span&gt;onMouseOver(FlexTableExt&amp;nbsp;&amp;nbsp;ft,&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;int&amp;nbsp;&lt;/span&gt;&lt;/b&gt;row){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ft.getRowFormatter().getElement(row).getStyle().setBackgroundColor(&lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;yellow&quot;&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;@Override&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;onMouseOut(FlexTableExt&amp;nbsp;&amp;nbsp;ft,&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;int&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;row){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ft.getRowFormatter().getElement(row).getStyle().setBackgroundColor(&lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;for&lt;/span&gt;&lt;/b&gt;( &lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;int &lt;/b&gt;&lt;/span&gt;r=0; r&amp;lt;10; r++){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;for&lt;/span&gt;&lt;/b&gt;(&lt;span style=&quot;color: #a64d79;&quot;&gt;&lt;b&gt;int &lt;/b&gt;&lt;/span&gt;c=0; c&amp;lt;5; c++){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ft.setText(r,c, &lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;cell &quot;&amp;nbsp;&lt;/span&gt;+ r +&amp;nbsp;&lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;,&quot;&amp;nbsp;&lt;/span&gt;+ c );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; ft.setRowEventsHandler(r,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;rowHandler&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/7757148842648885951/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2012/01/gwt-eventi-righe-per-flextable.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/7757148842648885951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/7757148842648885951'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2012/01/gwt-eventi-righe-per-flextable.html' title='GWT: eventi righe per FlexTable'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-3302199483916407713</id><published>2011-10-01T14:11:00.002+02:00</published><updated>2012-01-31T11:21:29.674+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><category scheme="http://www.blogger.com/atom/ns#" term="wireless"/><category scheme="http://www.blogger.com/atom/ns#" term="wlan"/><title type='text'>Come far funzionare la scheda wireless Broadcom 4303 su ubuntu</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Per far funzionare la scheda wireless Broadcom 4303 occorre il driver b43. Per installarlo aprite un terminale e scrivete:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;sudo apt-get install b43-fwcutter&lt;/b&gt;&lt;br /&gt;
una volta installato, riavviate il sistema e dal network manager (l&#39;icona vicino all&#39;orologio) selezionate &quot;Abilita rete senza fili&quot;.&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/3302199483916407713/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/10/come-far-funzionare-la-scheda-wireless.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/3302199483916407713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/3302199483916407713'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/10/come-far-funzionare-la-scheda-wireless.html' title='Come far funzionare la scheda wireless Broadcom 4303 su ubuntu'/><author><name>Gio</name><uri>http://www.blogger.com/profile/06159282382016275621</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS34oz8q2EneffXg-QSPANYU3rRSMhH2bq9b4KzhuA-M7xEYUSHvc3-u_0ZIvsmyNQw3mTZHIJ7zW74CJkDERlQe0gMf5-PtZ9mIkIpf-rMfh-SjVe2ueAErsq-mN2XQ/s220/gio4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-7603329564058842989</id><published>2011-09-29T19:04:00.050+02:00</published><updated>2019-12-20T14:36:23.370+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>GWT tutorial: GWT with PHP</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Typically, web applications developed in GWT imply the use of a Java application server (eg. Tomcat, Jetty, Glashfish, etc).&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;You can use a normal HTTP server like Apache or IIS to develop web services with server-side language of your choice.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Let us first of all how to create an ajax request into GWT client:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;
String url = &quot;http://localhost/myservice.php&quot;;
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
String postString = &quot;par1=val1&amp;amp;par2=val2&amp;amp;par3=val3&quot;;
builder.setHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
try {
    builder.sendRequest(postString, new RequestCallback(){
        @Override
        public void onResponseReceived(Request request, Response response) {
           if( 200==response.getStatusCode() ) {
               
               &lt;span style=&quot;background-color: yellow;&quot;&gt;String jsonString = response.getText();&lt;/span&gt;
               &lt;span style=&quot;background-color: yellow;&quot;&gt;MyObject myObj = parseJson(jsonString);&lt;/span&gt;
           }   
        }

        @Override
         public void onError(Request request, Throwable exception) {}
    });
}catch(RequestException e) {}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The &lt;code&gt;&quot;jsonString&quot;&amp;nbsp;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;must then be deserialized into an object.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;If we use the json format is sufficient to create a &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://code.google.com/intl/it-IT/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html&quot;&gt;JSNI&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;method&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;to execute the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: monospace; font-size: 13px; line-height: 18px;&quot;&gt;&quot;eval&quot;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;javascript&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;statement;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;if the format is in&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;font-size: 13px; line-height: 18px;&quot;&gt;XML&lt;/code&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;you can use a&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://code.google.com/intl/it-IT/webtoolkit/doc/latest/DevGuideCodingBasicsXML.html&quot;&gt;XMLparser&lt;/a&gt;.&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;native final &lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;MyObject&lt;/b&gt;&lt;/span&gt; parseJson(String json) &lt;span style=&quot;color: #999999;&quot;&gt;/*-{
   return eval(&quot;(&quot;+ json +&quot;)&quot;);
}-*/&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;where MyObject is a class which must extend &quot;JavaScriptObject&quot; and with methods needed to read the properties.&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;class &lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;MyObject&lt;/b&gt;&lt;/span&gt; extends JavaScriptObject {
    protected MyObject(){}
    public final native String getMyProperty1()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{ return this.myProperty1 }-*/&lt;/span&gt;;
    public final native int getMyProperty2()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{ return this.myProperty2 }-*/&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;json string returned from server should be something like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;{ &#39;myProperty1&#39;:&#39;hello&#39;, &#39;myProperty2&#39;:2534 }
&lt;/code&gt;&lt;/pre&gt;
&lt;code&gt;
&lt;/code&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;You can create in php like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php&lt;/span&gt;
$response = array(&#39;myProperty1&#39;=&amp;gt;&#39;hello&#39;, &#39;myProperty2&#39;=&amp;gt;2534);
echo json_encode($response);
&lt;span style=&quot;color: red;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;It&#39;s good practise to handle js error:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 13px; line-height: 18px;&quot;&gt;try {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; MyObject myObj = parseJson(jsonString);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 13px; line-height: 18px;&quot;&gt;}catch(JavaScriptException ex) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// handle parsing error&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 13px; line-height: 18px;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Said this, It remains, therefore, the problem of running service in &quot;debug mode&quot; on Eclipse (this modality uses a java application server listening on port 8888).&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The problem is due to &quot;cross domain&quot;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;browser&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;restrictions&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;On the client side, you are at &quot;127.0.0.1:8888&quot; (ip address debug mode) and you need to call a service at &quot;127.0.0.1:80&quot; (apache http server). The browser will not permit this.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;To solve this problem, I created a&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;GWT&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;service (RemoteServiceServlet) called &amp;nbsp;&lt;code&gt;DebugService&lt;/code&gt;&amp;nbsp;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;This service acts like a proxy and then simly submit your request by sending cookies (eg. php session id) and all HTTP POST parameters &amp;nbsp;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjggVQhpv_RkGuXa17tZtSRPxxygxKTilvq6AyltS9bj9w-NmDwAQQB2NFid5gNE2vkFRdVoSxzzTDipMIGhj9YJKrwlmsz8gddePD1jgrhyYAWJhDhcscooI1wUtVu-5KQNhPn0zGqIVqd/s1600/schema_gwt_php_service.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjggVQhpv_RkGuXa17tZtSRPxxygxKTilvq6AyltS9bj9w-NmDwAQQB2NFid5gNE2vkFRdVoSxzzTDipMIGhj9YJKrwlmsz8gddePD1jgrhyYAWJhDhcscooI1wUtVu-5KQNhPn0zGqIVqd/s400/schema_gwt_php_service.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Obviously you have to implement a code that checks when to use the debugging service, or contact the service php.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;For example, in this way:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;if( &amp;nbsp;GWT.getHostPageBaseURL().indexOf(&quot;http://127.0.0.1:8888&quot;) &amp;gt;= 0&amp;nbsp;){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; //call debug service (RemoteService)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; DebugServiceAsync debugService = GWT.create(DebugService.class);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; debugService.callJsonService(&quot;par1=val1&amp;amp;par2=val2&quot;,&quot;http://localhost/myService.php&quot;, new AsyncCallback&amp;lt;String&amp;gt;(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void onSuccess(String jsonString){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//TODO handle json string&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void onError(&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;Throwable caught&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// TODO handle error&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;}else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;//call php service (RequestBuilder)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;RequestBuilder builder = new RequestBuilder(&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;RequestBuilder&lt;/span&gt;.POST&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&quot;http://localhost/myService.php&quot;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &lt;/span&gt;&amp;nbsp; // ....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;DebugServiceImpl.java (pkg server)&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-style: solid; border-bottom-width: 1px; border-color: initial; border-image: initial; border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; font-size: 10px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import javax.servlet.http.Cookie;

import it.gheryd.testgwtphp.client.jsonServices.DebugService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class DebugServiceImpl extends RemoteServiceServlet implements DebugService {

 @Override
 public String callJsonService(String postParams, String url) {
   HttpURLConnection  conn = null;
   InputStream is = null;
   try {
     URL phpService = new URL( url );
     conn = (HttpURLConnection )phpService.openConnection();
     conn.addRequestProperty(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
     boolean useCookies = false;
     if(this.getThreadLocalRequest().getHeader(&quot;Cookie&quot;)!=null) {
       conn.addRequestProperty(&quot;Cookie&quot;, this.getThreadLocalRequest().getHeader(&quot;Cookie&quot;));
       useCookies = true;
     }
     if(postParams!=null &amp;amp;&amp;amp; postParams.length()&amp;gt;0 ) {
       conn.setDoOutput(true);
       OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
       out.write(postParams);
       out.close();
     }
     if (conn.getResponseCode() &amp;gt;= 400) {
       is = conn.getInputStream();
     } else {
       is = conn.getErrorStream();
     }
     is = conn.getInputStream();
     BufferedReader in = new BufferedReader( new InputStreamReader(is) );
     String jsonResponse = &quot;&quot;;
     String inputLine;
     while ((inputLine = in.readLine()) != null) jsonResponse += inputLine;
     in.close();
     if(useCookies){
        String headerName=null;
        for (int i=1; (headerName = conn.getHeaderFieldKey(i))!=null; i++) {
          if (headerName.equals(&quot;Set-Cookie&quot;)) {
              String cookie = conn.getHeaderField(i);
              cookie = cookie.substring(0, cookie.indexOf(&quot;;&quot;));
              String cookieName = cookie.substring(0, cookie.indexOf(&quot;=&quot;));
              String cookieValue = cookie.substring(cookie.indexOf(&quot;=&quot;) + 1, cookie.length());
              this.getThreadLocalResponse().addCookie(new Cookie(cookieName, cookieValue));
          }
        }
     }
         
     return jsonResponse;
   } catch(Exception ex) {
      this.log(&quot;errore in debug\n&quot;+&quot;url: &quot;+url+&quot;\nconn:&quot;+conn+&quot; \nis:&quot;+is, ex);
      return &quot;{type:\&quot;error\&quot;,value:{message:\&quot;&quot;+ex.getClass().getSimpleName()+&quot; - &quot;+ex.getMessage()+&quot;\&quot;}}&quot;;
   }
 }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;i&gt;DebugService.java (pkg client)&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-style: solid; border-bottom-width: 1px; border-color: initial; border-image: initial; border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; font-size: 10px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;


@RemoteServiceRelativePath(&quot;debugService&quot;)
public interface DebugService extends RemoteService {

 public String callJsonService( String postParams, String url );
 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;i&gt;DebugServiceAsync .java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-style: solid; border-bottom-width: 1px; border-color: initial; border-image: initial; border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; font-size: 10px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface DebugServiceAsync {

 void callJsonService(String postParams, String url, AsyncCallback&lt;string&gt; callback);

}
&lt;/string&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The service JAVA must be declared in the file&amp;nbsp;&lt;i&gt;/ WEB-INF/web.xml:&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left-color: rgb(0, 170, 0); border-left-style: solid; border-left-width: 7px; padding-left: 7px;&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
         version=&quot;2.5&quot;
         xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;&amp;gt;

  &amp;lt;!-- Servlets --&amp;gt;
  
  &amp;lt;!-- Default page to serve --&amp;gt;
  &amp;lt;welcome-file-list&amp;gt;
    &amp;lt;welcome-file&amp;gt;TestGwtPhp.html&amp;lt;/welcome-file&amp;gt;
  &amp;lt;/welcome-file-list&amp;gt;
  &lt;b&gt;
  &amp;lt;servlet&amp;gt;
    &amp;lt;servlet-name&amp;gt;debugService&amp;lt;/servlet-name&amp;gt;
    &amp;lt;servlet-class&amp;gt;it.gheryd.testgwtphp.server.DebugServiceImpl&amp;lt;/servlet-class&amp;gt;
  &amp;lt;/servlet&amp;gt;
  
  &amp;lt;servlet-mapping&amp;gt;
    &amp;lt;servlet-name&amp;gt;debugService&amp;lt;/servlet-name&amp;gt;
    &amp;lt;url-pattern&amp;gt;/testgwtphp/debugService&amp;lt;/url-pattern&amp;gt;
  &amp;lt;/servlet-mapping&amp;gt;&lt;/b&gt;
&amp;lt;/web-app&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;At this point you know what you need to make an application with which you can make debugging of Eclipse (or NetBeans).&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;If you want to see a practical example, after you find a project that I hope will be clarified.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In this project I created a series of classes under the package &quot;jsonService&quot; that automate the ajax request&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The Eclipse project has this structure:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE4L9TdaGlS3aO-mef_2WZm2wEm2hx9msA6JvS6OBQAo2NQtcBiZjbddApj0SCuEleeAzYfTRWu_isW1_HR7UJ1FubpPAfHiSn_cQ9Y-AM1-ztYbn5cN_E6IdoPzmTRSpoeD7ZytMF5JZ6/s1600/eclipse_gwt_php.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE4L9TdaGlS3aO-mef_2WZm2wEm2hx9msA6JvS6OBQAo2NQtcBiZjbddApj0SCuEleeAzYfTRWu_isW1_HR7UJ1FubpPAfHiSn_cQ9Y-AM1-ztYbn5cN_E6IdoPzmTRSpoeD7ZytMF5JZ6/s400/eclipse_gwt_php.png&quot; width=&quot;194&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;As you can see, the files &quot;. php&quot; are in the &quot;war&quot; folder of the project.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In my example I added in the configuration file&amp;nbsp;&lt;code&gt;httpd.conf&lt;/code&gt;&amp;nbsp;Apache alias:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;i&gt;httpd.conf&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left-color: rgb(0, 170, 0); border-left-style: solid; border-left-width: 7px; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;Alias /testgwtphp &quot;C:/Users/gheryd/workspace/TestGwtPhp/war/&quot; &lt;/span&gt;
&amp;lt;Directory &quot;C:/Users/gheryd/workspace/TestGwtPhp/war/&quot;&amp;gt;
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
 Deny from all
 Allow from 127.0.0.1
&amp;lt;/Directory&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;for which the services in PHP HTTP Server can be accessed at&amp;nbsp;&lt;i&gt;&quot;http://localhost/testgwtphp/&quot;.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In the package&amp;nbsp;&lt;code&gt;it.gheryd.testgwtphp.client.jsonServices&lt;/code&gt;&amp;nbsp;find the classes that use it for calls to PHP services.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The class&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: monospace; font-size: 13px; line-height: 18px;&quot;&gt;JsonService is used&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;to create a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: monospace; font-size: 13px; line-height: 18px;&quot;&gt;ajax&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;request&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;font-size: 13px; line-height: 18px;&quot;&gt;.&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;This class&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;automatically&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;decides&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;whether to make&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;the request directly&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;to the service&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;or&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;whether to call&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;PHP&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;DebugService&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps atn&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;RemoteServiceServlet&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;It also takes care&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;to deserialize&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;the JSON string&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;bean&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #333333; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 18px;&quot;&gt;The code below is highlighted in yellow the url used in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;code style=&quot;line-height: 18px;&quot;&gt;debug&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-small; line-height: 18px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-small; line-height: 18px;&quot;&gt;mode.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;JsonService.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptException;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class JsonService {

 private static final String TYPE_ERROR = &quot;error&quot;;
 private static final String BASE_SERVICE_URL =  GWT.getHostPageBaseURL();
&lt;span style=&quot;background-color: yellow;&quot;&gt;private static final String BASE_DEBUG_SERVICEURL = &quot;http://127.0.1.1/testgwtphp/&quot;;&lt;/span&gt;
 
 public static boolean DEBUG = false;
 private DebugServiceAsync debugService =null;
 
 private String serviceUrl = null;
 
 
 public JsonService(String serviceUrl) {
  this.serviceUrl = serviceUrl;
 }
 
 public &amp;lt;T extends JavaScriptObject&amp;gt; void request(String jsonParams, JsonServiceCallback&amp;lt;T&amp;gt; callback) {
  try {
   String postString = createPostString(jsonParams);
   if(DEBUG) 
    startDebugRequest(postString, callback );
   else
    startRequest(postString, callback );
  }catch(JavaScriptException ex) {
   callback.onError(&quot;javascript exception: &quot;+ex.getMessage()+&quot; jsonParams: &quot;+jsonParams);
  }
 }
 
 
 public &amp;lt;T extends JavaScriptObject&amp;gt; void request(Map&amp;lt;String,String&amp;gt; paramsMap, JsonServiceCallback&amp;lt;T&amp;gt; callback) {
  String postString = createPostString(paramsMap);
  if(DEBUG)
   startDebugRequest(postString, callback );
  else 
   startRequest(postString, callback);
 }
 
 
 private &amp;lt;T extends JavaScriptObject&amp;gt; void startDebugRequest(String postString, final JsonServiceCallback&amp;lt;T&amp;gt; callback) {
  if(debugService==null) {
   debugService = GWT.create(DebugService.class);
  }
  String url = BASE_DEBUG_SERVICEURL+serviceUrl;
  debugService.callJsonService(postString, url, new AsyncCallback&amp;lt;String&amp;gt;() {
   
   @Override
   public void onSuccess(String result) {
    handleSuccess(result, callback);
   }
   
   @Override
   public void onFailure(Throwable caught) {
    callback.onError(caught.getMessage());
   }
  });
 }
 
 
 private &amp;lt;T extends JavaScriptObject&amp;gt; void startRequest(String postString,  final JsonServiceCallback&amp;lt;T&amp;gt; callback) {
  String url = BASE_SERVICE_URL+serviceUrl;
  
  RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
  builder.setHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
  
  try{
   builder.sendRequest(postString, new RequestCallback(){
    @Override
    public void onResponseReceived(Request request, Response response) {
     if( 200==response.getStatusCode() ) {
      handleSuccess(response.getText(), callback);
     }else {
      callback.onError( &quot;error status:&quot;+response.getStatusCode() );
     }    
    }

    @Override
    public void onError(Request request, Throwable exception) {
     callback.onError(exception.getMessage()); 
    }
    
   });
  }catch(RequestException e){
   callback.onError(e.getMessage());
  }
 }
 
 private &amp;lt;T extends JavaScriptObject&amp;gt; void handleSuccess(String json, JsonServiceCallback&amp;lt;T&amp;gt; callback) {
  ResponseBean responseBean = null;
  try {
   responseBean = deserializeResponse( json );
  }catch(JavaScriptException exception) {
   callback.onError(&quot;javascript exception: &quot;+exception.getMessage()+&quot; json-&amp;gt;&quot;+json);
   return;
  }
  
  if( TYPE_ERROR.equals(responseBean.getType()) ) {
   try {
    ErrorBean errorBean = (ErrorBean)responseBean.getValue();
    callback.onError( errorBean.getMessage() );
   }catch(JavaScriptException exception){
    callback.onError(&quot;error object deserialization:&quot;+exception.getMessage()+&quot; json: &quot;+json );
   }
   
   return;
  }
  callback.onSuccess( (T)responseBean.getValue() );
 }
 
 private final native ResponseBean deserializeResponse(String json) /*-{
  var response = eval( &quot;(&quot;+json+&quot;)&quot; );
  if( !response.type ) throw &quot;type is undefined&quot;;
  if( response.value===undefined ) throw &quot;value is undefined&quot;;
  if( typeof(response.value) == &quot;string&quot; ) {
   response.value = {&quot;str&quot;:response.value};
  }
  return response;
 }-*/;
 
 private final native String createPostString(String json)/*-{
  if(!json) return null;
  var obj = eval( &quot;(&quot;+json+&quot;)&quot; );
  var s = &quot;&quot;;
  for(var k in obj) {
   s += (s.length==0?&quot;&quot;:&quot;&amp;amp;&quot;) + k + &quot;=&quot; + obj[k];
  }
  return s;
 }-*/;

 private String createPostString(Map&amp;lt;String,String&amp;gt; paramsMap) {
  if(paramsMap==null || paramsMap.size()==0 ) return null;
  String s = &quot;&quot;;
  for(String k: paramsMap.keySet()) {
   s += (s.length()==0?&quot;&quot;:&quot;&amp;amp;&quot;) + k + &quot;=&quot; + paramsMap.get(k);
  }
  return s;
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The interface JsonServiceCallback is similar to that of GWT&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;AsyncCallback&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;; in a similar manner should implement this interface to manage the response in case of success or failure.&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;JsonServiceCallback.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

public interface JsonServiceCallback &amp;lt;T extends JavaScriptObject&amp;gt; {
 
 public void onSuccess(T result);
 public void onError(String error);
 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The classes&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;ResponseBean&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;ErrorBean&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;are used internally to&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;JsonService&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;, and define the formats of the data that the service must return PHP (explained in more detail below)&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;ResponseBean.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

class ResponseBean  extends JavaScriptObject { 
 protected ResponseBean(){}
 
 public final native String getType() /*-{
  return this.type;
 }-*/;
 
 public final native JavaScriptObject getValue() /*-{
  return this.value;
 }-*/;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;i&gt;ErrorBean.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

public class ErrorBean extends JavaScriptObject {

 protected ErrorBean() {}
  
 public final native String getMessage() /*-{
  return this.message;
 }-*/;  
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The class&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;JsString&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;is used if the data value returned by the service&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;PHP&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;is a simple string.&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;JsString.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

public class JsString extends JavaScriptObject{

 protected JsString() {}
  
 public final native String getString()/*-{
  return this.str;
 }-*/;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;For completeness also follows the content of the GWT module configuration file:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;i&gt;TestGwtPhp.gwt.xml&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;module rename-to=&#39;testgwtphp&#39;&amp;gt;
&amp;lt;!-- module rename-to=&#39;testgwtphp&#39; --&amp;gt;
  &amp;lt;!-- Inherit the core Web Toolkit stuff.                        --&amp;gt;
  &amp;lt;inherits name=&#39;com.google.gwt.user.User&#39;/&amp;gt;

  &amp;lt;!-- Inherit the default GWT style sheet.  You can change       --&amp;gt;
  &amp;lt;!-- the theme of your GWT application by uncommenting          --&amp;gt;
  &amp;lt;!-- any one of the following lines.                            --&amp;gt;
  &amp;lt;inherits name=&#39;com.google.gwt.user.theme.clean.Clean&#39;/&amp;gt;
  &amp;lt;!-- &amp;lt;inherits name=&#39;com.google.gwt.user.theme.standard.Standard&#39;/&amp;gt; --&amp;gt;
  &amp;lt;!-- &amp;lt;inherits name=&#39;com.google.gwt.user.theme.chrome.Chrome&#39;/&amp;gt; --&amp;gt;
  &amp;lt;!-- &amp;lt;inherits name=&#39;com.google.gwt.user.theme.dark.Dark&#39;/&amp;gt;     --&amp;gt;

  &amp;lt;!-- Other module inherits                                      --&amp;gt;

  &amp;lt;!-- Specify the app entry point class.                         --&amp;gt;
  &amp;lt;entry-point class=&#39;it.gheryd.testgwtphp.client.TestGwtPhp&#39;/&amp;gt;

  &amp;lt;!-- Specify the paths for translatable code                    --&amp;gt;
  &amp;lt;source path=&#39;client&#39;/&amp;gt;
  &amp;lt;source path=&#39;shared&#39;/&amp;gt;

&amp;lt;/module&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Now that we have defined the basic classes for asynchronous communication client / server, including debug mode, we explain how to use this system.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;To make an ajax call is sufficient to instantiate the class and pass the url on JsonService of our service:&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;JsonService myService = new JsonService(&quot;MyService.php&quot;);&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;so the request will be made by calling the &quot;request&quot;:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;myService.request(null, new JsonServiceCallback&amp;lt;MyBean&amp;gt;(){
    public void onSuccess(MyBean result) {
        //TODO response ok
    }
    public void onError(String error) {
       //TODO error
    }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The bean that will return me the service is to extend the class &quot;com.google.gwt.core.client.JavaScriptObject&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;public class MyBean extends JavaScriptObject {
    protected MyBean() {}
    public final native String getMyProperty()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
        return this.myPropery;
    }-*/&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;PHP side of the service will return a JSON string in this format:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;{
   type: &quot;MyBean&quot;,
   value: {myProperty: &quot;Hello World!&quot; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;or in case of error&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;{
   type: &quot;error&quot;,
   value: {message: &quot;This is a error&quot;}
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;To pass the POST data in PHP Service must create a hash map:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;Map&amp;lt;String,String&amp;gt; postParams = new HashMap&amp;lt;String,String&amp;gt;();
postParams.put(&quot;myparam&quot;, &quot;myvalue&quot;);
myService.request(postParams, new JsonServiceCallback&amp;lt;MyBean&amp;gt;(){
    public void onSuccess(MyBean result) {
        //TODO response ok
    }
    public void onError(String error) {
       //TODO error
    }
});&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;or alternatively you can pass a json string:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;String postParams = &quot;{&#39;myparam&#39;:&#39;myvalue&#39;}&quot;;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The service php must be something like this:&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php&lt;/span&gt;
if( !isset($_POST[&quot;myparam&quot;]) ) {
    echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;error&quot;, &quot;value&quot;=&amp;gt;array(&quot;message&quot;=&amp;gt;&quot;missing post param&quot;) ));
    return;
}
echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;MyBean&quot;, &quot;value&quot;=&amp;gt;array(&quot;myProperty&quot;=&amp;gt;&quot; gwt-php test &quot;) ));
&lt;span style=&quot;color: red;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;As already explained, the service can return a simple string.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In this case you must use the class&amp;nbsp;&lt;code&gt;JsString&lt;/code&gt;&amp;nbsp;:&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;myService.request(postParams, new JsonServiceCallback&amp;lt;JsString&amp;gt;(){
    public void onSuccess(JsString result) {
        String s = result.getStr();
        //TODO response ok
    }
    public void onError(String error) {
       //TODO error
    }
});&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The json response will then simply:&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;{
   type: &quot;MyBean&quot;,
   value: &quot;Hello World!&quot;
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;b&gt;Sample implementation&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In applying the test that I developed using the PHP session to store the names entered by the user via the GUI.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The look and feel of this page:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3-CjsgJLit75si272b5vLj6ImzgoHb1aP8MXsQIhnC1oA1qccazdWbkLdr7uRQUwo3XpccKi20WCrB-s6wpEM6osaeq9ebHYj0tz5rSKFPJnrkPb1cN9sEjnBByG8INJ9qSpvlDVt-6V/s1600/test-gwt-php.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;288&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3-CjsgJLit75si272b5vLj6ImzgoHb1aP8MXsQIhnC1oA1qccazdWbkLdr7uRQUwo3XpccKi20WCrB-s6wpEM6osaeq9ebHYj0tz5rSKFPJnrkPb1cN9sEjnBByG8INJ9qSpvlDVt-6V/s400/test-gwt-php.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In the class&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: white; font-size: 13px; line-height: 18px;&quot;&gt;JsonService&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;was configured as the base url for use in debugging PHP services:&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;private static final String BASE_DEBUG_SERVICEURL = &quot;http://127.0.1.1/testgwtphp/&quot;;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;To enable debug mode should lead to&amp;nbsp;&lt;code&gt;true&lt;/code&gt;&amp;nbsp;the static variable class&amp;nbsp;&lt;code&gt;JsonService&lt;/code&gt;&amp;nbsp;, you can set it to automatically:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;JsonService.DEBUG = GWT.getHostPageBaseURL().indexOf(&quot;http://127.0.0.1:8888&quot;) &amp;gt;= 0;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;At this point we see the GWT module of the test.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;i&gt;TestGwtPhp.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client;

import java.util.HashMap;
import java.util.Map;

import it.gheryd.testgwtphp.client.jsonServices.JsString;
import it.gheryd.testgwtphp.client.jsonServices.JsonService;
import it.gheryd.testgwtphp.client.jsonServices.JsonServiceCallback;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;


/**
 * Entry point classes define &amp;lt;code&amp;gt;onModuleLoad()&amp;lt;/code&amp;gt;.
 */
public class TestGwtPhp implements EntryPoint {

 private JsonService addUserService = new JsonService(&quot;AddUserService.php&quot;);
 private JsonService getUsersService = new JsonService(&quot;GetUsersService.php&quot;);
 private JsonService deleteUsersService = new JsonService(&quot;DeleteUsers.php&quot;);
 
 public void onModuleLoad() {
  
  final SimplePanel resultPanel = new SimplePanel();
  resultPanel.getElement().getStyle().setBackgroundColor(&quot;#EEE&quot;);
  resultPanel.getElement().getStyle().setProperty(&quot;border&quot;, &quot;1px solid black&quot;);
  resultPanel.getElement().getStyle().setProperty(&quot;padding&quot;, &quot;10px&quot;);
  
  VerticalPanel vp = new VerticalPanel();
  vp.setSpacing(10);
  
  final TextBox nameTB = new TextBox();
  final TextBox surnameTB = new TextBox();
  final CheckBox debugCB = new CheckBox(&quot;debug&quot;);
  
  HorizontalPanel hp = new HorizontalPanel();
  hp.add( new HTML(&quot;name: &quot;) );
  hp.add( nameTB );
  hp.add( new HTML(&quot;surname: &quot;) );
  hp.add( surnameTB );
  vp.add(hp);
  
  Button addUserBtn = new Button(&quot;add user&quot;);
  Button getUsersBtn = new Button(&quot;get users&quot;);
  Button deleteUsersBtn = new Button(&quot;delete users&quot;);
  
  hp = new HorizontalPanel();
  hp.add(addUserBtn);
  hp.add(getUsersBtn);
  hp.add(deleteUsersBtn);
  hp.add(debugCB);
  
  vp.add(hp);
  vp.add(resultPanel);
  final VerticalPanel usersPanel = new VerticalPanel();
  vp.add(usersPanel);
  
  debugCB.addClickHandler(new ClickHandler() {
   @Override
   public void onClick(ClickEvent event) {
    JsonService.DEBUG = debugCB.getValue();
    resultPanel.setWidget( new HTML(&quot;debug mode: &quot;+JsonService.DEBUG) );
   }
  });
  
  debugCB.setValue( GWT.getHostPageBaseURL().indexOf(&quot;http://127.0.0.1:8888&quot;) &amp;gt;= 0 , true );
  
  JsonService.DEBUG = debugCB.getValue();
  
  addUserBtn.addClickHandler(new ClickHandler() {
   @Override
   public void onClick(ClickEvent event) {
    
    Map&amp;lt;String,String&amp;gt; params = new HashMap&amp;lt;String,String&amp;gt;();
    params.put(&quot;name&quot;, nameTB.getText());
    params.put(&quot;surname&quot;, surnameTB.getText());
    addUserService.request(params, new JsonServiceCallback&amp;lt;JsString&amp;gt;(){

     @Override
     public void onSuccess(JsString result) {
      resultPanel.setWidget( new HTML(&quot;Result: &quot;+result.getString()) );
     }

     @Override
     public void onError(String error) {
      resultPanel.setWidget( new HTML(&quot;&amp;lt;span style=\&quot;color:red;\&quot;&amp;gt;ERROR!&amp;lt;/span&amp;gt; &quot;+error) );
     }
     
    });
   }
  });
  
  getUsersBtn.addClickHandler(new ClickHandler() {
   @Override
   public void onClick(ClickEvent event) {
    usersPanel.clear();
    String params = null;
    getUsersService.request(params,  new JsonServiceCallback&amp;lt;JsArray&amp;lt;UserBean&amp;gt;&amp;gt;(){

     @Override
     public void onSuccess(JsArray&amp;lt;UserBean&amp;gt; result) {
      resultPanel.setWidget( new HTML(&quot;users: &quot;+result.length()) );
      for(int i=0; i&amp;lt;result.length(); i++) {
       UserBean ub = result.get(i);
       usersPanel.add( new HTML( ub.getName()+&quot; &quot;+ub.getSurname() ) );
      }
     }

     @Override
     public void onError(String error) {
      resultPanel.setWidget( new HTML(&quot;&amp;lt;span style=\&quot;color:red;\&quot;&amp;gt;ERROR!&amp;lt;/span&amp;gt; &quot;+error) );
     }
     
    });
    
   }
  });
  
  deleteUsersBtn.addClickHandler(new ClickHandler(){
   @Override
   public void onClick(ClickEvent event) {
    String params = null;
    deleteUsersService.request(params, new JsonServiceCallback&amp;lt;JsString&amp;gt;() {
     @Override
     public void onSuccess(JsString result) {
      resultPanel.setWidget( new HTML(&quot;Result: &quot;+result.getString()) );
     }

     @Override
     public void onError(String error) {
      resultPanel.setWidget( new HTML(&quot;&amp;lt;span style=\&quot;color:red;\&quot;&amp;gt;ERROR!&amp;lt;/span&amp;gt; &quot;+error) );
     }
     
    });
    
   }
  });
  
  RootPanel.get().add(vp);
  
 }
 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;It &#39;s interesting use of the class&amp;nbsp;&lt;a href=&quot;http://translate.googleusercontent.com/translate_c?hl=it&amp;amp;rurl=translate.google.com&amp;amp;tl=en&amp;amp;twu=1&amp;amp;u=http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/core/client/JsArray.html&amp;amp;usg=ALkJrhjS5BQHUoMdv8syWJWYONJGVCdQWg&quot; style=&quot;color: #757575; text-decoration: none;&quot;&gt;&lt;code&gt;JsArray&lt;/code&gt;&lt;/a&gt;&amp;nbsp;(see gwt api) used to switch the list of objects&amp;nbsp;&lt;code&gt;UserBean&lt;/code&gt;&amp;nbsp;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Not necessarily have to use a bean object that you define, you can pass any object that extends&amp;nbsp;&lt;a href=&quot;http://translate.googleusercontent.com/translate_c?hl=it&amp;amp;rurl=translate.google.com&amp;amp;tl=en&amp;amp;twu=1&amp;amp;u=http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/core/client/JavaScriptObject.html&amp;amp;usg=ALkJrhg3AxyX7oaIhbvsOkLeXKuLjpO03Q&quot; style=&quot;color: #757575; text-decoration: none;&quot;&gt;&lt;code&gt;JavaScriptObject&lt;/code&gt;&lt;/a&gt;&amp;nbsp;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The bean that I used is as follows:&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;i&gt;UserBean.java&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client;

import com.google.gwt.core.client.JavaScriptObject;

public class UserBean extends JavaScriptObject {
 protected UserBean() {}

 public final native String getName()/*-{
  return this.name;
 }-*/;
  
 public final native String getSurname()/*-{
  return this.surname;
 }-*/; 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;And finally the PHP services used:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;i&gt;AddUserService.php&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php&lt;/span&gt; 

if( !isset($_POST) ) {
 echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;error&quot;, &quot;value&quot;=&amp;gt;array(&quot;message&quot;=&amp;gt;&quot;missing post params&quot;))  );
 return;
}else if( empty($_POST[&quot;name&quot;]) ) {
 echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;error&quot;, &quot;value&quot;=&amp;gt;array(&quot;message&quot;=&amp;gt;&quot;missing post param &#39;name&#39;&quot;))  );
 return;
}else if( empty($_POST[&quot;surname&quot;])  ) {
 echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;error&quot;, &quot;value&quot;=&amp;gt;array(&quot;message&quot;=&amp;gt;&quot;missing post param &#39;surname&#39;&quot;))  );
 return;
}

$name = $_POST[&quot;name&quot;];
$surname = $_POST[&quot;surname&quot;];

session_start();

$response = array();

if( !isset($_SESSION[&quot;list&quot;]) ) $_SESSION[&quot;list&quot;] = array();
 
$_SESSION[&quot;list&quot;][] = array(&quot;name&quot;=&amp;gt;$name, &quot;surname&quot;=&amp;gt;$surname);

$response[&quot;type&quot;] = &quot;result&quot;;
$response[&quot;value&quot;] = &quot;ok&quot;;

echo json_encode($response);

&lt;span style=&quot;color: red;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;i&gt;DeleteUsers.php&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php&lt;/span&gt; 

session_start();

unset($_SESSION[&quot;list&quot;]);

echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;result&quot;, &quot;value&quot;=&amp;gt;&quot;ok&quot;) );

&lt;span style=&quot;color: red;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;i&gt;GetUsersService.php&lt;/i&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php&lt;/span&gt; 

session_start();

if( !isset($_SESSION[&quot;list&quot;]) )  {
 echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;error&quot;, &quot;value&quot;=&amp;gt;array(&quot;message&quot;=&amp;gt;&quot;no list in session&quot;))  );
 return;
};

$response = array(&quot;type&quot;=&amp;gt;&quot;userList&quot; );
$response[&quot;value&quot;] = $_SESSION[&quot;list&quot;];

echo json_encode($response);
&lt;span style=&quot;color: red;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;We can now run our application from Eclipse:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCx_8xAolTOyaibg_8pUkzvuySjKguEgPolNiWFgiLue2RAIolvlcweAgYqCKIOmXGk262vM6vpDHoZnmLqslrG3xXgKPMBp6D45ub0tfM6KDTbcSKHE7_U_w0NJxUlShr3C1PsO-nS_3a/s1600/testgwtphp_run.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;203&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCx_8xAolTOyaibg_8pUkzvuySjKguEgPolNiWFgiLue2RAIolvlcweAgYqCKIOmXGk262vM6vpDHoZnmLqslrG3xXgKPMBp6D45ub0tfM6KDTbcSKHE7_U_w0NJxUlShr3C1PsO-nS_3a/s400/testgwtphp_run.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;while to run the application directly from Apache, you must first compile it:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimsJHtlmVku2nHDsUk_LvyJ_AELsiOR4kijzcgSkq96jZ0mrgQ5Id9XoYQpD1wbTglnRSDDVLDswSF1l6FBmo4RDKU9gPATizj32eB6MqVAt1ylJP_syAU-hGPYYXcnobtkWG2sWhVdXbF/s1600/testgwtphp_compile.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;290&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimsJHtlmVku2nHDsUk_LvyJ_AELsiOR4kijzcgSkq96jZ0mrgQ5Id9XoYQpD1wbTglnRSDDVLDswSF1l6FBmo4RDKU9gPATizj32eB6MqVAt1ylJP_syAU-hGPYYXcnobtkWG2sWhVdXbF/s400/testgwtphp_compile.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Once completed you can access the url &quot;127.0.0.1/testgwtphp/TestGwtPhp.html&quot;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Remember to start Apache!&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&lt;b&gt;Deepening&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;I have not focused on the operation of the class&amp;nbsp;&lt;code&gt;JsonService&lt;/code&gt;&amp;nbsp;but if the look is not very complex.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;It&#39;s definitely improved in several respects.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;u&gt;Error Handling&lt;/u&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;For example, error handling is dealt with very easily if not trivial, but in a real application would be more practical to treat the error as if it were an exception.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In this case the interface&amp;nbsp;&lt;code&gt;ErrorBean&lt;/code&gt;&amp;nbsp;could be enriched by other properties such as the name of an exception report to the client.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;For example, if the session expired the service may respond with an error like this:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;{
    type: &quot;error&quot;,
    value: {message:&quot;session expired&quot;, exception:&quot;SessionExpiredException&quot;} 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; font-size: 16px;&quot;&gt;Then create&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; font-size: 16px;&quot;&gt;a class&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; font-size: 16px;&quot;&gt;exception&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; font-size: 16px;&quot;&gt;on the&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hps&quot; style=&quot;color: #333333; font-size: 16px;&quot;&gt;client package&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 16px;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;public class SessionExpiredException extends Exception {
    public SessionExpiredException (String message) {  
       super(message);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In this case the method&amp;nbsp;&lt;code&gt;onError&lt;/code&gt;&amp;nbsp;interface&amp;nbsp;&lt;code&gt;JsonServiceCallback&lt;/code&gt;&amp;nbsp;this will be the exception rather than the message string.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

public interface JsonServiceCallback &lt;t extends=&quot;&quot; javascriptobject=&quot;&quot;&gt; {
 
 public void onSuccess(T result);
 public void onError(Exception Ex);
 
}
&lt;/t&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;To verify the type of exception would be enough to control implementation&amp;nbsp;&lt;code&gt;JsonServiceCallback&lt;/code&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;myService.request(null, new JsonServiceCallback&amp;lt;MyBean&amp;gt;(){
    public void onSuccess(MyBean result) {
        //TODO response ok
    }
    public void onError(Exception ex) {
       if(ex instanceof SessionExpired) {
           //TODO session expired
       }else {
           //Window.alert(ex.getMessage());
       }
    }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In the class&amp;nbsp;&lt;code&gt;JsonService&lt;/code&gt;&amp;nbsp;must be passed the instance of an exception:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;if( &quot;SessionExpiredException&quot;.equals(errorBean.getException()) )
   callback.onError( new SessionExpiredException(errorBean.getMessage()) );
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Obviously you must add the property &quot;exception&quot; in the class&amp;nbsp;&lt;code&gt;ErrorBean&lt;/code&gt;&amp;nbsp;:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px solid; font-size: 10px; padding: 10px;&quot;&gt;&lt;code&gt;package it.gheryd.testgwtphp.client.jsonServices;

import com.google.gwt.core.client.JavaScriptObject;

public class ErrorBean extends JavaScriptObject {

 protected ErrorBean() {}
  
 public final native String getMessage() /*-{
  return this.message;
 }-*/; 
 
 public final native String getException() /*-{
  return this.exception;
 }-*/; 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;u&gt;The methods JSNI&lt;/u&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;When you create a class that extends JavascriptObject, care must be taken to the return type in JSNI methods.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;In the following sample code is provided, for example, the type of return value:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;
public  class MyObject extends JavaScriptObject{
    protected MyObject(){}
    public final native int getIntNumber()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
        return isNaN(this.intNumber)?0:this.intNumber;
    }-*/&lt;/span&gt;;
    public final native String getSomeString()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
        return typeof(this.someString)==&quot;string&quot;? this.someString : &quot;&quot;;
    }-*/&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;This avoids errors in the code difficult to detect.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Within JSNI methods you can put a notification to identify the causes of the error:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;
public  class MyObject extends JavaScriptObject{
    protected MyObject(){}
    public final native int getIntNumber()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
        if(isNaN(this.intNumber)){
            console.log(&quot;***error***&quot;);
            console.log(this);
            this.intNumber = 0;
        }
        return this.intNumber;
    }-*/&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;u&gt;Hash Map&lt;/u&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;If a service needs to return a map of objects (an associative array in PHP), client-side GWT we can implement a class for the purpose:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;
public class JHashMap &amp;lt;V extends JavaScriptObject&amp;gt; extends JavaScriptObject{
     protected JHashMap(){}
     public final native JsArrayString keys()&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
         return this.keys;
     }-*/&lt;/span&gt;;
     public final native V get(String key)&lt;span style=&quot;color: #999999;&quot;&gt;/*-{
         return this.values[key];
     }-*/&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;PHP side of the map should be created as:&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;?php&lt;/span&gt;
    $objectList = array(
        &quot;obj1&quot; =&amp;gt; array(&quot;property1&quot;=&amp;gt;&quot;value1&quot;,&quot;property2&quot;=&amp;gt;&quot;value2&quot;),
        &quot;obj2&quot; =&amp;gt; array(&quot;property1&quot;=&amp;gt;&quot;value1&quot;,&quot;property2&quot;=&amp;gt;&quot;value2&quot;),
        &quot;obj3&quot; =&amp;gt; array(&quot;property1&quot;=&amp;gt;&quot;value1&quot;,&quot;property2&quot;=&amp;gt;&quot;value2&quot;)
    );
    $map = array(
         &quot;keys&quot; =&amp;gt; array_keys($objectList),
         &quot;values&quot; =&amp;gt; $objectList
    );
    echo json_encode( array(&quot;type&quot;=&amp;gt;&quot;JHashMap&quot;, &quot;value&quot;=&amp;gt;$map ) );
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;From GWT client we manage well the answer:&lt;/span&gt;
&lt;br /&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;
myservice.request(null, new JsonServiceCallback&amp;lt;&lt;/code&gt;JHashMap&amp;lt;MyBean&amp;gt; &amp;gt;&lt;jhashmap&gt;(){&lt;/jhashmap&gt;&lt;/pre&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;jhashmap&gt;     @Override
     public void onSuccess(JHashMap&amp;lt;&lt;/jhashmap&gt;&lt;/code&gt;MyBean&amp;gt; result) {&lt;/pre&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;         JsArrayString keys = result.keys();&lt;/pre&gt;
&lt;pre style=&quot;border-left: #0A0 7px solid; padding-left: 7px;&quot;&gt;&lt;code&gt;&lt;jhashmap&gt;         for(int i=0; i&amp;lt;keys.length(); i++ ){
             MyBean myBean = result.get(keys.get(i));
             // ....
         }
     }

     @Override
     public void onError(String error) {
        //handle error
     }
});
&lt;/jhashmap&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/7603329564058842989/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/09/gwt-tutorial-utilizzare-gwt-con-php.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/7603329564058842989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/7603329564058842989'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/09/gwt-tutorial-utilizzare-gwt-con-php.html' title='GWT tutorial: GWT with PHP'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjggVQhpv_RkGuXa17tZtSRPxxygxKTilvq6AyltS9bj9w-NmDwAQQB2NFid5gNE2vkFRdVoSxzzTDipMIGhj9YJKrwlmsz8gddePD1jgrhyYAWJhDhcscooI1wUtVu-5KQNhPn0zGqIVqd/s72-c/schema_gwt_php_service.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-4398877144435500853</id><published>2011-09-17T15:43:00.004+02:00</published><updated>2012-02-05T17:24:36.784+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="html"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>HTML: Utilizzo corretto degli attributi</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Indice dei tutorials:&amp;nbsp;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Conoscere l&#39;uso appropriato di questi attributi può semplificare il codice HTML, CSS e JAVASCRIPT e ritengo agevoli la manutenzione.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Attributo &quot;id&quot;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Quando il browser carica una pagina, verifica l&#39;esistenza di questo attributo. Se l&#39;attributo &quot;id&quot; viene specificato su un tag, il browser aggiunge il riferimento al relativo elemento in una mappa. Così in javascript è possibile accedere velocemente all&#39;elemento con questa istruzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;myId&quot;);&lt;/span&gt;&lt;br /&gt;
Questa istruzione restituisce un solo elemento HTML.&lt;br /&gt;
Se il valore dell&#39;attributo &quot;id&quot; fosse duplicato, l&#39;istruzione javascript non lavorerebbe adeguatamente.&lt;br /&gt;
&lt;b&gt;Quindi il valore di un &quot;id&quot; non deve essere duplicato&lt;/b&gt; come in questo esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;div id=&quot;&lt;u&gt;container&lt;/u&gt;&quot;&amp;gt;...&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #990000;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;lt;div &lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;id=&quot;&lt;u&gt;container&lt;/u&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;gt;...&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
Alcuni grafici css utilizzano l&#39;attributo &quot;id&quot; per definire uno stile CSS:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #93c47d;&quot;&gt;#container {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #93c47d;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;padding: 10px;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #93c47d;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
ma come spiegato precedentemente, lo scopo dell&#39;attributo &quot;id&quot; è quello di accedere in maniera veloce ad un determinato elemento tramite javascript.&lt;br /&gt;
Per Definire le proprietà grafiche consiglio di far riferimento all&#39;attributo &quot;class&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;Attributo &quot;class&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Questo attributo viene utilizzato per assegnare ad un certo elemento HTML uno stile grafico definito tramite foglio di stile CSS.&lt;br /&gt;
Molti utilizzano l&#39;attributo &quot;id&quot; perché danno per scontato che quell&#39;elemento sarà unico. Tuttavia, dato che spesso e volentieri le strutture grafiche di una pagina HTML subiscono cambiamenti nel tempo, è sempre meglio utilizzare riferimenti all&#39;attributo &quot;class&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;&lt;u&gt;mainContainer&lt;/u&gt;&quot;&amp;gt;...&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
perché cambiando il valore della classe, e quindi l&#39;aspetto grafico, non sarà necessario modificare per quanto possibile il codice javascript che probabilmente utilizzerà gli attributi &quot;id&quot; per accedere agli elementi html.&lt;br /&gt;
In realtà con alcune librerie javascript (es.jquery) è possible utilizzare uno dei valori di &quot;class&quot; per accedere ad uno o più elementi (vedere la sezione &quot;Selettori jQuery&quot;).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Attributo &quot;name&quot;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
In questa sezione parleremo dell&#39;attributo &quot;name&quot; in riferimento agli elementi &amp;nbsp;(input,select) usati nel form (questo attributo può essere utilizzato anche sul tag &quot;&amp;lt;iframe&amp;gt;&quot;, &amp;lt;a&amp;gt; o &amp;lt;img&amp;gt;, per esempio).&lt;br /&gt;
Quindi, nel contesto di un form, questo attributo viene utilizzato per specificare i parametri da inviare al server con il metodo &quot;GET&quot; o &quot;POST&quot;.&lt;br /&gt;
A differenza dell&#39;attributo &quot;id&quot;, può aver senso duplicare il valore di questo attributo su piu tag in due casi:&lt;br /&gt;
1.Attributo name duplicato su diversi form:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form id=&quot;form1&quot; method=&quot;POST&quot; action=&quot;url1&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;indirizzo casa:&amp;lt;input &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;name=&quot;&lt;b&gt;address&lt;/b&gt;&quot;&lt;/span&gt; type=&quot;text&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;button type=&quot;submit&quot; &amp;gt;invia&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form id=&quot;form2&quot; method=&quot;post&quot; action=&quot;url2&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;indirizzo ufficio&amp;lt;input&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt; name=&quot;&lt;b&gt;address&lt;/b&gt;&quot;&lt;/span&gt; type=&quot;text&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;button type=&quot;submit&quot; &amp;gt;invia&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
Come potete constatare, esistono due campi &quot;input&quot; che hanno lo stesso valore dell&#39;attributo &quot;name&quot;, ma sono inseriti in due form diversi. Quindi il submit in un form non crea conflitto con l&#39;altro input inserito nell&#39;altro form.&lt;br /&gt;
&lt;br /&gt;
2. Attributo duplicato su un elemento &quot;submit&quot;:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;form id=&quot;form1&quot; method=&quot;POST&quot; action=&quot;url1&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;indirizzo casa:&amp;lt;input&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;name=&quot;&lt;b&gt;address&lt;/b&gt;&quot;&lt;/span&gt;&amp;nbsp;type=&quot;text&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;input type=&quot;submit&quot; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;name=&quot;azione&lt;/span&gt;&quot; value=&quot;aggiungi&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;input type=&quot;submit&quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt; name=&quot;azione&quot;&lt;/span&gt; value=&quot;cancella&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In questo caso il valore che arriverà al server dipende dal bottone premuto. Se infatti viene premuto il tasto con name=&quot;aggiungi&quot;, al server verranno invitati in POST i valori &quot;address&quot; (che dipende da ciò che è inserito nella textbox) e azione=&quot;aggiungi&quot;. Se invece viene premuto il tasto &quot;cancella&quot;, verrà inviato sempre &quot;address&quot; e azione =&quot;cancella&quot;. Quindi a seconda del valore &quot;azione&quot;, il codice lato server sa cosa deve fare con il valore di &quot;address&quot;. Se in form prevede un solo tasto, potrebbe non esser necessario specificare l&#39;attributo name per il tasto &quot;submit&quot;.&lt;br /&gt;
&lt;br /&gt;
Alcuni usano mettere il valore dell&#39;attributo &quot;id&quot; uguale al valore dell&#39;attributo &quot;name&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;input id=&quot;address&quot; name=&quot;address&quot; type=&quot;text&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
Questo non è necessario perché come è stato spiegato l&#39;attributo &quot;id&quot; viene utilizzato lato client (codice javascript) mentre l&#39;attributo &quot;name&quot; definisce il parametro da inviare al server.&lt;br /&gt;
Tuttavia è possibile via javascript utilizzare &quot;name&quot; per accedere direttamente ad un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var addressEl = document.getElementById(&quot;form1&quot;).&lt;b&gt;address&lt;/b&gt;;&lt;/span&gt;&lt;br /&gt;
anche se consiglio sempre l&#39;attributo &quot;id&quot;. Uno dei motivi è spiegato in seguito.&lt;br /&gt;
Un errore comune che può capitare è assegnare all&#39;attributo &quot;name&quot; un valore che in javascript potrebbe&lt;br /&gt;
scatenare un errore in quanto il suo valore corrisponde ad una parola riservata javascript.&lt;br /&gt;
Per esempio:&lt;br /&gt;
&lt;span style=&quot;color: #999999;&quot;&gt;&amp;lt;input type=&quot;submit&quot; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: red; color: white;&quot;&gt;name=&quot;submit&quot;&lt;/span&gt;&lt;span style=&quot;color: #999999;&quot;&gt; value=&quot;invia&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
se vogliamo avviare il &quot;submit&quot; di un form tramite javascript si genera un errore.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;form1&quot;).submit();&lt;/span&gt;&lt;br /&gt;
per il semplice motivo che la proprietà &amp;nbsp;&quot;submit&quot; non fa più riferimento ad una funzione ma ad un elemento del form. Dato che chi scrive &amp;nbsp;HTML non deve necessariamente conoscere javascript, per il programmatore javascript, onde evitare questi imprevisti è sconsigliabile accedere agli elementi tramite l&#39;attributo name.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;Selettore jQuery&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
jQuery fornisce una potente e semplice funzionalità per selezionare uno o più elementi sulla nostra pagina HTML tramite il nome di classi e nomi di attributi (nei browser di ultima generazione questo tipo di selezione si può effettuare anche in javascript nativo):&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var list = jQuery(&quot;input[name=address] .lighted&quot;);&lt;/span&gt;&lt;br /&gt;
Tuttavia questo potente strumento deve essere usato in maniera adeguata se non vogliamo compromettere le prestazioni di esecuzione del codice.&lt;br /&gt;
Per esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;$(&quot;&lt;b&gt;.myButtonDiv&lt;/b&gt;&quot;).click(function(event){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;clicked&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
Questo selettore può essere molto pesante su certi browser e su certe tipologie di computer (es.netbook) in quanto richiede una lunga scansione di tutti gli elementi della pagina HTML.&lt;br /&gt;
In questo caso, per migliorare le prestazioni, può aver senso aggiungere un attributo &quot;id&quot; al contenitore degli elementi che vogliamo selezionare:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;$(&quot;&lt;b&gt;#menuContainer .myButtonDiv&lt;/b&gt;&quot;).click(function(event){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;clicked&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
Questo è sicuramente più veloce perché identifichiamo prima di tutto un elemento contenitore tramite l&#39;attributo &quot;id&quot; che come già spiegato avviene in maniera veloce, e successivamente vengono cercati tutti i suoi elementi figli con la classe &quot;myButtonDiv&quot;. Quindi la ricerca è limitata solo agli elementi figli del contenitore e non a tutto il documento HTML.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/4398877144435500853/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/09/html-utilizzo-corretto-degli-attributi.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4398877144435500853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4398877144435500853'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/09/html-utilizzo-corretto-degli-attributi.html' title='HTML: Utilizzo corretto degli attributi'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-1884045824428599958</id><published>2011-08-07T20:49:00.015+02:00</published><updated>2012-04-20T10:09:00.249+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>javascript numeri primi</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Indice dei tutorials:&amp;nbsp;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Utilizzando un semplice script ho implementato qualcosa di simile al &lt;i&gt;Crivello di Eratostene&lt;/i&gt; per determinare i numeri primi fino ad un certo numero.&lt;br /&gt;
Questo semplice esempio ci consentirà poi di fare qualche analisi su come ottimizzare le performance di esecuzione.&lt;br /&gt;
&lt;br /&gt;
Per eseguirlo basta copiare il contenuto del box in un file .html e aprirlo con il browser.&lt;br /&gt;
&lt;br /&gt;
Eccovi quello che dovrebbe comparire:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvYeOzUpVgei-Dd38_wN0ADzmjx13fG642p0aumGzv2uDRp_WJxUt7aSsgWp5jtEJbfn5eSARicl4sjA4dtuXw5jn4RifMfEg4lccP2O9QFCvulsK4wZH31goYDZqfuBuNcs6_k0LYYwKQ/s1600/numeri_primi.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvYeOzUpVgei-Dd38_wN0ADzmjx13fG642p0aumGzv2uDRp_WJxUt7aSsgWp5jtEJbfn5eSARicl4sjA4dtuXw5jn4RifMfEg4lccP2O9QFCvulsK4wZH31goYDZqfuBuNcs6_k0LYYwKQ/s400/numeri_primi.png&quot; width=&quot;314&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-bottom-color: rgb(68, 68, 68); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(68, 68, 68); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(68, 68, 68); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(68, 68, 68); border-top-style: solid; border-top-width: 1px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;
&lt;pre style=&quot;color: #444444;&quot;&gt;&lt;code&gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;
var primes;
function onClickHandler() {&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;    var startTime = (new Date()).getTime();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;color: #444444;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;    primes = [2];
    var n = parseInt( document.getElementById(&quot;endN&quot;).value );
    if(isNaN(n)) {
       alert(&quot;Is not a number!&quot;);
       return;
    }
    var tbody = document.createElement(&quot;tbody&quot;);
    var tr = document.createElement(&quot;tr&quot;);
    tbody.appendChild(tr);
    for(var i=1; i&amp;lt;=n; i++) {
       if( i%10==1 ){
          tr = document.createElement(&quot;tr&quot;);
          tbody.appendChild(tr);
       }
       var td = document.createElement(&quot;td&quot;);
       td.appendChild( document.createTextNode(i) );
       td.style.border = &quot;1px solid gray&quot;;
       if( isPrimeNumber(i) )
           td.style.backgroundColor = &quot;magenta&quot;;
       tr.appendChild(td);
    }
    var table = document.createElement(&quot;table&quot;);
    table.setAttribute(&quot;cellPadding&quot;, &quot;5&quot;);
    table.appendChild(tbody);
    var container = document.getElementById(&quot;container&quot;);
    container.innerHTML = &quot;&quot;;
    container.appendChild(document.createTextNode(&quot;trovati: &quot;+primes.length));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: #444444;&quot;&gt;    &lt;/span&gt;container.appendChild(document.createTextNode(&quot; tempo [s]: &quot;+((new Date()).getTime()-startTime)/1000  ) );&lt;span style=&quot;color: #444444;&quot;&gt;
    &lt;/span&gt;container.appendChild(table);
}

function isPrimeNumber(n) {
    if(n==2) return true;
    else if(n==1 || n%2==0) return false;
    for(var j=0; j&amp;lt;primes.length; j++)
        if( n%primes[j]==0 ) return false;
    primes.push(n);
    return true;
}&lt;span style=&quot;color: #444444;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #444444;&quot;&gt;
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
   &amp;lt;input id=&quot;endN&quot; name=&quot;endN&quot; &amp;nbsp;type=&quot;text&quot; type=&quot;text&quot; /&amp;gt;
   &amp;lt;br/&amp;gt;
   &amp;lt;button onclick=&quot;onClickHandler()&quot;&amp;gt;search&amp;lt;/button&amp;gt;
   &amp;lt;div id=&quot;container&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Spiegazione.&lt;br /&gt;
Sulla funzione &quot;onClickHandler&quot; viene creata una tabella. Successivamente la tabella viene popolata con i numeri interi positivi fino alla cifra indicata nella textbox.&lt;br /&gt;
Con la funzione &quot;isPrimeNumber&quot; viene verificato se il numero è primo, in tal caso alla cella che viene aggiunto uno sfondo viola per evidenziare questa caratteristica.&lt;br /&gt;
Nella funzione &quot;isPrimeNumber&quot;, man mano che viene richiamata, viene aggiunto nella variabile array &quot;primes&quot; l&#39;eventuale numero primo.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ottimizzazione.&lt;br /&gt;
Se si esegue lo script per numeri molto alti (per esempio un milione), i tempi di esecuzione potrebbe essere piuttosto lunghi.&lt;br /&gt;
E&#39; possibile ottimizzare i tempi di esecuzione dello script con un controllo all&#39;interno del ciclo che crea le celle della tabella. Infatti si potrebbe aggiungere una variabile contatore che viene azzerata quando raggiunge il valore 10. Quando la variabile assume i valori 2,4,5,6,8,10 sicuramente il numero non è primo, quindi è inutile chiamare la funzione isPrimeNumber che esegue ogni volta un ciclo su tutti i numeri primi. &lt;br /&gt;
Chiaramente questo controllo non deve essere fatto al primo giro. Ecco un esempio:&lt;br /&gt;
&lt;pre style=&quot;font-size: 11px;&quot;&gt;&lt;code&gt;
var c = 1;
for(var i=1; i&amp;lt;=n; i++) {
    ...
    var isPrime = (c!=i &amp;amp;&amp;amp; (c%2==0 || c==5)) || isPrimeNumber(i);
    if(c==10) c = 1; else c++;
    if( isPrime )
           td.style.backgroundColor = &quot;magenta&quot;;
    tr.appendChild(td);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/1884045824428599958/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/08/javascript-numeri-primi.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1884045824428599958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1884045824428599958'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/08/javascript-numeri-primi.html' title='javascript numeri primi'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvYeOzUpVgei-Dd38_wN0ADzmjx13fG642p0aumGzv2uDRp_WJxUt7aSsgWp5jtEJbfn5eSARicl4sjA4dtuXw5jn4RifMfEg4lccP2O9QFCvulsK4wZH31goYDZqfuBuNcs6_k0LYYwKQ/s72-c/numeri_primi.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-8291197467032090880</id><published>2011-08-01T00:24:00.007+02:00</published><updated>2011-08-03T22:36:05.387+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="network"/><category scheme="http://www.blogger.com/atom/ns#" term="rfkill"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu  11.04"/><category scheme="http://www.blogger.com/atom/ns#" term="wireless"/><category scheme="http://www.blogger.com/atom/ns#" term="wlan"/><title type='text'>UBUNTU 11.04 wireless disabled</title><content type='html'>&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/08/ubuntu-1104-wireless-disabled.html&amp;sl=it&amp;tl=en&amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Recentemente mi è capitato di avere disattivata la scheda wireless.&lt;br /&gt;
Ho provato con il comando:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;color:#FFF;background-color:#000&quot;&gt;gheryd@gheryd:~$ &lt;b&gt;sudo ifconfig wlan0 up&lt;/b&gt;
&lt;/pre&gt;&lt;br /&gt;
e mi è comparso un messaggio di errore che indicava un blocco rfkill.&lt;br /&gt;
Cercando su web ho trovato informazioni su questo pagina:&lt;br /&gt;
&lt;a href=&quot;http://linuxwireless.org/en/users/Documentation/rfkill&quot;&gt;http://linuxwireless.org/en/users/Documentation/rfkill&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Quindi ho verificato che esisteva un blocco software tramite il seguente comando&lt;br /&gt;
&lt;pre style=&quot;color:#FFF;background-color:#000&quot;&gt;&lt;code&gt;gheryd@gheryd:~$ &lt;b&gt;rfkill list&lt;/b&gt;&lt;/code&gt;
&lt;/pre&gt;&lt;br /&gt;
Questo comando vi elenca lo stato dei blocchi su vari dispositivi (wireless, bluetooth, etc).&lt;br /&gt;
Per esempio se avete disabilitato la scheda wireless tramite l&#39;apposito tasto sul vostro computer vi verrà segnalato un &quot;hard blocked: yes&quot;, se invece è stata disabilitata via software vi verrà segnalato &quot;soft blocked: yes&quot;.&lt;br /&gt;
Nel mio caso la wireless avevo un blocco software, per ripristinare ho effettuato il comando&lt;br /&gt;
&lt;pre style=&quot;color:#FFF;background-color:#000&quot;&gt;&lt;code&gt;gheryd@gheryd:~$ &lt;b&gt;rfkill unblock all&lt;/b&gt;&lt;/code&gt;
&lt;/pre&gt;Poi ho riavviato la scheda  wireless&lt;br /&gt;
&lt;pre style=&quot;color:#FFF;background-color:#000&quot;&gt;&lt;code&gt;gheryd@gheryd:~$ &lt;b&gt;sudo ifconfig wlan0 up&lt;/b&gt;&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/8291197467032090880/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/08/ubuntu-1104-wireless-disabled.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/8291197467032090880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/8291197467032090880'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/08/ubuntu-1104-wireless-disabled.html' title='UBUNTU 11.04 wireless disabled'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-724523430082139247</id><published>2011-07-31T12:27:00.021+02:00</published><updated>2011-08-28T11:25:02.038+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="lamp"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu  11.04"/><category scheme="http://www.blogger.com/atom/ns#" term="web developer tools"/><title type='text'>Ubuntu 11.04 installazioni per developer</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/07/ubuntu-1104-installazioni-per-developer.html&amp;amp;sl=it&amp;amp;tl=en&amp;amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Per chi lavora in ambito web, è necessario avere un&#39;installazione LAMP (Linux Apache MySql Php) e in generale di tutti i tools di sviluppo.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;LAMP&lt;/u&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;&lt;code&gt;gheryd@gheryd:~$ &lt;b&gt;sudo apt-get install apache2&lt;/b&gt;

gheryd@gheryd:~$ &lt;b&gt;sudo apt-get install php5 libapache2-mod-php5&lt;/b&gt;

gheryd@gheryd:~$ &lt;b&gt;sudo apt-get install mysql-server mysql-client&lt;/b&gt;

gheryd@gheryd:~$ &lt;b&gt;sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin&lt;/b&gt;

gheryd@gheryd:~$ &lt;b&gt;sudo /etc/init.d/apache2 restart&lt;/b&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Per maggiori dettagli vedere la pagina:&lt;br /&gt;
&lt;a href=&quot;http://www.howtoforge.com/ubuntu_lamp_for_newbies&quot;&gt;http://www.howtoforge.com/ubuntu_lamp_for_newbies&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Test&lt;/u&gt;&lt;br /&gt;
Provate sul browser &quot;http:/localhost/&quot;, dovreste vedere la pagina &quot;It works!&quot;.&lt;br /&gt;
Create nella directory &quot;/var/www&quot; il file phpinfo.php con i seguente contenuto&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;lt;?php phpinfo(); ?&amp;gt;&lt;/span&gt;&lt;br /&gt;
All&#39;indirizzo &quot;http:/localhost/phpinfo.php&quot; dovreste vedere le informazioni di php.&lt;br /&gt;
Infine all&#39;indirizzo &quot;http:/localhost/phpmyadmin/&quot; dovreste accedere alla pagina di &quot;PhpMyAdmin&quot;.&lt;br /&gt;
&lt;br /&gt;
Su seguente link trovate informazioni sulla configurazione del logging di php:&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/ubuntu-php-configurare-log-error.html&quot;&gt;http://gheryd.blogspot.com/2011/05/ubuntu-php-configurare-log-error.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tools di sviluppo web.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;JAVA Sun/Oracle&lt;/u&gt;&lt;br /&gt;
Installare java sun/oracle (istruzioni dal sito &lt;a href=&quot;http://www.chimerarevo.com/2011/05/25/installare-java-6-update-25-su-ubuntu-11-04-natty-ppa/&quot;&gt;http://www.chimerarevo.com/2011/05/25/installare-java-6-update-25-su-ubuntu-11-04-natty-ppa/&lt;/a&gt;):&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$sudo add-apt-repository ppa:chimerarevo/java
gheryd@gheryd:~$sudo apt-get update
gheryd@gheryd:~$sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin sun-java6-fonts
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Guake&lt;/u&gt;&lt;br /&gt;
Una console sempre pronta ed elegante che scende dall&#39;altro premendo F12&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install guake
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Meld&lt;/u&gt;&lt;br /&gt;
Programma per verificare differenze tra file e fare il merge.&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install meld
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Aptana&lt;/u&gt;&lt;br /&gt;
E&#39; un potente editor basato su eclipse. Potete così lavorare su html, css, javascript, php, etc. E&#39; scaricabile dal sito: &lt;a href=&quot;http://www.aptana.com/&quot;&gt;http://www.aptana.com/&lt;/a&gt;&lt;br /&gt;
nota: per utilizzare aptana è necessario java sun.&lt;br /&gt;
In alternativa si pu&amp;ograve; installare Eclipse e aggiungere aptana come plugin.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Geany&lt;/u&gt;&lt;br /&gt;
E un editor più semplice di aptana, molto leggero ma funzionale.&lt;br /&gt;
Per installarlo è sufficiente eseguire il comando da console:&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install geany
&lt;/pre&gt;Una volta installato consiglio di attivare tutti i plugin (da menu: Strumenti-&gt;gestione plugin)&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Filezilla&lt;/u&gt;&lt;br /&gt;
Per poter caricare o scaricare files su server via FTP è molto comodo utilizzare filezilla, per installarlo digitare sul console:&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install filezilla
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Gimp&lt;/u&gt;&lt;br /&gt;
Per elaborare immagini e fotografie. Anche i programmatori talvolta si devono cimentare con queste operazioni grafiche&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install gimp
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Inkscape&lt;/u&gt;&lt;br /&gt;
A differenza di Gimp, questo strumento serve per elaborare immagini di tipo vettoriale (Es.SVG), nel caso si è rivelato potente per vettorializzare una immagine bitmap.&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white; font-size: 11px; padding: 5px;&quot;&gt;gheryd@gheryd:~$ sudo apt-get install inkscape
&lt;/pre&gt;&lt;br /&gt;
&lt;u&gt;Virtual Box&lt;/u&gt;&lt;br /&gt;
Per testare le vostre pagine web su Internet Explorer occorre avere una macchina virtuale&lt;br /&gt;
Windows che potete creare con Virtual Box. &lt;br /&gt;
Potete scaricare il pacchetto deb dal link:&lt;br /&gt;
&lt;a href=&quot;http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html&quot;&gt;http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html&lt;/a&gt;&lt;br /&gt;
Dopo aver installato Virtual Box (lo potete aprire dal menu sotto la voce System Tools), installatevi &quot;Extension Pack&quot; sempre dal link indicato sopra.&lt;br /&gt;
Per creare una macchina virtuale dovete avere un file .iso con il sistema operativo oppure il cd. Create una macchina virtuale (il file ha estensione .vdi). La dimensione che io ho scelto per il disco virtuale è di 10GB. Una volta creato la macchina, avviatela, vi verrà chiesto la posizione del file .iso o del cd con il sistema operativo da installare.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Strumenti Browser&lt;/u&gt;&lt;br /&gt;
Se siete dei grafici o degli sviluppatori javascript &quot;spinti&quot;, beh dotatevi di un web console come si deve! &lt;br /&gt;
Su firefox installatevi l&#39;estensione &quot;firebug&quot;.&lt;br /&gt;
Su chrome avete gia lo strumento accessibile dal menù &quot;strumenti-&amp;gt;strumenti per sviluppatori&quot;. La versione di google chrome ora è disponibile per linux: &lt;a href=&quot;http://www.google.com/chrome?hl=it&quot;&gt;http://www.google.com/chrome?hl=it&lt;/a&gt;&lt;br /&gt;
Altre informazioni le trovate nel post&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Ottimizzare Ubuntu&lt;/u&gt;&lt;br /&gt;
Per chi lavora con Ubuntu, è importante avere un sistema veloce ed affidabile.&lt;br /&gt;
Attualmente sto provando XFCE e lo trovo estremamente più veloce rispetto a Unity o Gnome.&lt;br /&gt;
E&#39; semplice, non vi aspettate effetti grafici avanzati. Ma quando si lavora non credo che siano così importanti ;)&lt;br /&gt;
Per installare XFCE è sufficiente eseguire il seguente comando:&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white;&quot;&gt;&lt;code&gt;gheryd@gheryd-sm:~$ &lt;b&gt;sudo apt-get install xfce4&lt;/b&gt;&lt;/code&gt;&lt;/pre&gt;Il desktop viene attivato dalla finestra di login: selezionate la vostra utenza e poi sul pannello in basso selezionate XFCE.&lt;br /&gt;
Provate ad usarlo, vi renderete conto subito delle notevoli prestazioni. Potete personalizzarlo come meglio credete usato i soliti comandi. &lt;br /&gt;
Ecco la mia personalizzazione:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfAI4pHZoVZnt0yOY9u3MyhW-wshVDzADPsoFN-W-Hy66GNq8PRiuEHUAziOp550OKV53BMLZqV2HfJRrAD_Gu3z3NygMo1vXNiQa5i2WqgU5Q9iRDRMEzkBeIJA2CyCFk6RFT2eAQtBrw/s1600/Schermata.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfAI4pHZoVZnt0yOY9u3MyhW-wshVDzADPsoFN-W-Hy66GNq8PRiuEHUAziOp550OKV53BMLZqV2HfJRrAD_Gu3z3NygMo1vXNiQa5i2WqgU5Q9iRDRMEzkBeIJA2CyCFk6RFT2eAQtBrw/s400/Schermata.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Una caratteristica che ho apprezzato oltre alla velocità, è la stabilita dei pannelli, nessun problema con icone di notifica, skype, etc.&lt;br /&gt;
Oltre all&#39;utilizzo di xfce, ho migliorato le performance seguendo questo tutorial:&lt;br /&gt;
&lt;a href=&quot;http://www.chimerarevo.com/2011/07/26/6-consigli-utili-per-velocizzare-ubuntu-11-04/&quot;&gt;http://www.chimerarevo.com/2011/07/26/6-consigli-utili-per-velocizzare-ubuntu-11-04/&lt;/a&gt;&lt;br /&gt;
Ricordo che si può ritornare al desktop GNOME o UNITY dalla finestra di login.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/724523430082139247/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/07/ubuntu-1104-installazioni-per-developer.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/724523430082139247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/724523430082139247'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/07/ubuntu-1104-installazioni-per-developer.html' title='Ubuntu 11.04 installazioni per developer'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfAI4pHZoVZnt0yOY9u3MyhW-wshVDzADPsoFN-W-Hy66GNq8PRiuEHUAziOp550OKV53BMLZqV2HfJRrAD_Gu3z3NygMo1vXNiQa5i2WqgU5Q9iRDRMEzkBeIJA2CyCFk6RFT2eAQtBrw/s72-c/Schermata.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-4653008414149012151</id><published>2011-07-17T10:19:00.023+02:00</published><updated>2012-09-25T13:57:02.837+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>Javascript le basi (2a parte)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&amp;amp;sl=it&amp;amp;tl=en&amp;amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Indice dei tutorials:&amp;nbsp;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Indice&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;operazioni matematiche&lt;/li&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;array&lt;/li&gt;
&lt;li&gt;date&lt;/li&gt;
&lt;li&gt;funzione &lt;i&gt;void&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;funzioni &lt;i&gt;timer&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;funzioni globali di javascript&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;u&gt;&lt;i&gt;&lt;b&gt;Operazioni matematiche&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Oltre alle operazioni aritmentiche, in javascript è possibile effettuare operazioni trigonometriche, logaritmiche, etc utilizzando l&#39;oggetto&amp;nbsp;&lt;i&gt;Math&lt;/i&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.abs(a) &amp;nbsp; &amp;nbsp; //&amp;nbsp;&lt;i&gt;the absolute value of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.acos(a) &amp;nbsp; &amp;nbsp;//&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&amp;nbsp;arc cosine of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.asin(a) &amp;nbsp; &amp;nbsp;//&amp;nbsp;&lt;i&gt;arc sine of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.atan(a) &amp;nbsp; &amp;nbsp;//&amp;nbsp;&lt;u&gt;&lt;i&gt;arc tangent of a&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.atan2(a,b) //&lt;i&gt;&amp;nbsp;arc tangent of a/b&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.ceil(a) &amp;nbsp; &amp;nbsp;// &amp;nbsp;&lt;i&gt;integer closest to a and not less than a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.cos(a) &amp;nbsp; &amp;nbsp; //&amp;nbsp;&lt;i&gt;cosine of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.exp(a) &amp;nbsp; &amp;nbsp; //&lt;i&gt;&amp;nbsp;exponent of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.floor(a) &amp;nbsp; //&lt;i&gt;&amp;nbsp;integer closest to a, not greater than a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.log(a) &amp;nbsp; &amp;nbsp; //&lt;i&gt;&amp;nbsp;log of a base e&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.max(a,b) &amp;nbsp; //&lt;i&gt;&amp;nbsp;the maximum of a and b&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.min(a,b) &amp;nbsp; //&amp;nbsp;&lt;i&gt;the minimum of a and b&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.pow(a,b) &amp;nbsp; //&lt;i&gt;&amp;nbsp;a to the power b&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.random() &amp;nbsp; //&lt;i&gt;&amp;nbsp;pseudorandom number 0 to 1&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.round(a) &amp;nbsp; //&amp;nbsp;&lt;i&gt;integer closest to a&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.sin(a) &amp;nbsp; &amp;nbsp; //&amp;nbsp;&lt;i&gt;sine of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.sqrt(a) &amp;nbsp; &amp;nbsp;//&amp;nbsp;&lt;i&gt;square root of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Math.tan(a) &amp;nbsp; &amp;nbsp; //&amp;nbsp;&lt;i&gt;tangent of a&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;u&gt;&lt;i&gt;&lt;b&gt;String&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
Come abbiamo visto nella prima parte, possiamo creare una stringa in questa maniera:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Hello world&quot;;&lt;/span&gt;&lt;br /&gt;
in alternativa è possible creare una stringa istanziando un oggetto String:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = new String(&quot;Hello world&quot;);&lt;/span&gt;&lt;br /&gt;
Questo ci ricorda che una stringa è un oggetto che possiede metodi e proprietà.&lt;br /&gt;
Ad esempio, per sapere quanti caratteri ci sono in una stringa:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var l = s.length;&lt;/span&gt;&lt;br /&gt;
Per verificare se una stringa è vuota si può verificare in questo modo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( s.length==0 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;String is void&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
equivalente a:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( s==&quot;&quot; ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;alert(&quot;String is void&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
ma il primo modo dovrebbe essere più veloce perchè viene verificato un numero, il secondo richiede un confronto tra stringhe che è un pochino più lento.&lt;br /&gt;
L&#39;oggetto String offre diversi utili metodi che spiego in seguito.&lt;br /&gt;
&lt;br /&gt;
Dato un carattere separatore, è possibile ottenere un array di stringhe:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var words = &quot;Hello world!&quot;.split(&quot; &quot;); // &lt;i&gt;words =&amp;nbsp;[&quot;Hello&quot;, &quot;world&quot;];&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Posso limitare i valori della lista specificando nel secondo argomento il numero massimo di stringhe da restituire:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;uno,due, tre,quattro,cinque&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var list = s.split(&quot;,&quot;, 3); //&lt;i&gt; list = [&quot;uno&quot;, &quot;due&quot;, &quot;tre&quot;];&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Per ottenere una porzione di una string si possono utilizzare due metodi:&lt;br /&gt;
- &lt;i&gt;substr&lt;/i&gt;(startpos, length)&lt;br /&gt;
- &lt;i&gt;slice&lt;/i&gt;(startpos, endpos)&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ecco degli esempi:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Javascript is good!&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;subst&lt;/b&gt;r(11, 2); &amp;nbsp;/&lt;i&gt;/s2 = &quot;is&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
le posizioni partono da 0.&lt;br /&gt;
Passando solo il primo parametro viene estratta una stringa fino alla fine:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;subst&lt;/b&gt;r(11); &amp;nbsp;//&lt;i&gt;s2 = &quot;is good!&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Il metodo splice è simile a substr, ma come secondo argomento non si specifica la lunghezza, ma la posizione finale:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;slice&lt;/b&gt;(11, 13); &amp;nbsp;//&lt;i&gt;s2 = &quot;is&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Senza il secondo argomento, si comporta come substr&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;slice&lt;/b&gt;(11); &amp;nbsp;//&lt;i&gt;s2 = &quot;is good!&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Se viene specificato un valore negativo, la posizione si intende relativa rispetto la fine della stringa:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;slice&lt;/b&gt;(-6); &amp;nbsp;//&lt;i&gt;s2 = &quot;good!&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
cioè sono estratti gli ultimi 5 caratteri.&lt;br /&gt;
&lt;br /&gt;
Conversione lettere maiuscole, minuscole:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;HelloWorld!&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s1 = s.&lt;b&gt;toUpperCase&lt;/b&gt;(); &amp;nbsp; //&lt;i&gt; s1 = &quot;HELLO WORLD!&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;toLowerCase&lt;/b&gt;(); &amp;nbsp; // &lt;i&gt;s2 = &quot;hello world!&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ricercare una porzione di stringa&lt;br /&gt;
- &lt;i&gt;indexOf&lt;/i&gt;(String)&lt;br /&gt;
- &lt;i&gt;lastIndexOf&lt;/i&gt;(String)&lt;br /&gt;
- &lt;i&gt;search&lt;/i&gt;(regular expression)&lt;br /&gt;
- &lt;i&gt;march&lt;/i&gt;(regular expression)&lt;br /&gt;
Esempi:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Javascript is good!&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var pos = s.&lt;b&gt;search&lt;/b&gt;(&quot;is&quot;); &amp;nbsp;/&lt;i&gt;/pos = 11&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;uno due tre&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Sostituzione:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&quot;Javascript is good!&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.&lt;b&gt;replace&lt;/b&gt;(&quot;Javascript&quot;, &quot;Java&quot;); //&amp;nbsp;&lt;i&gt;s2 = &quot;Java is good!&quot;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
Sostituzione multipla:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;ABABABAB&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.replace(/A/g, &quot;C&quot;); &lt;i&gt;&amp;nbsp;// s2 = &quot;CBCBCBCB&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
per la sostituzione multipla è stato utilizzata un&#39;espressione regolare, il termine &quot;g&quot; alla fine dell&#39;espressione effettua la selezione multipla. In generale è possibile utilizzare questa semplice espressione in questo modo&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var newString = s.replace(/&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;oldString&lt;/span&gt;/g, &quot;newString&quot;);&lt;/span&gt;&lt;br /&gt;
in cui al posto di &quot;oldString&quot; verrà inserito il termine da rimpiazzare.&lt;br /&gt;
Segue un altro esempio in cui sono sostituiti gli spazi con i trattini:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Questo è un test&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.replace(/\s+/g, &quot;-&quot;); &lt;i&gt;&amp;nbsp;// s2 = &quot;Questo-è-un-test&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Il termine &quot;\s+&quot; indica uno o più spazi nelle regular expression.&lt;br /&gt;
In alternativa si sarebbe potuto scrivere:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s.split(&quot; &quot;).join(&quot;-&quot;);&amp;nbsp;&amp;nbsp;&lt;i&gt;// s2 = &quot;Questo-è-un-test&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&quot;join&quot; è un metodo dell&#39;oggetto array e serve a unire in una stringa tutti i suoi elementi(vedi sezione array).&lt;br /&gt;
&lt;br /&gt;
Trim:&lt;br /&gt;
l&#39;oggetto String non prevede la funzione &quot;trim&quot; (la rimozione di spazi all&#39;inizio e alla fine di una stringa); con la seguente istruzione risolvete il problema:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&quot; &amp;nbsp; &amp;nbsp;Hello! &amp;nbsp; &amp;nbsp; &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;s = s.replace(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;/^\s+|\s+$/g, &quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;); &amp;nbsp; &amp;nbsp;&lt;i&gt;// s = &quot;&lt;/i&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Hello!&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&quot;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Informazioni sui caratteri&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s =&amp;nbsp;&amp;nbsp;&quot;Javascript is good!&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = s.&lt;b&gt;charAt&lt;/b&gt;(11); &amp;nbsp;//&lt;i&gt; c = &quot;i&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var unicode = s.&lt;b&gt;charCodeAt&lt;/b&gt;(11) &amp;nbsp; &amp;nbsp;//&lt;i&gt; unicode = 105, codice unicode per il carattere &quot;i&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = String.&lt;b&gt;fromCharCode&lt;/b&gt;(105); &amp;nbsp; //&amp;nbsp;&lt;i&gt;c = &quot;i&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;i&gt;Array&lt;/i&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Definire un array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr = [10, &quot;test&quot;, false];&lt;/span&gt;&lt;br /&gt;
oppure&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr = new Array(10, &quot;test&quot;, false);&lt;/span&gt;&lt;br /&gt;
Valore di un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var item = arr[2];&lt;/span&gt;&lt;br /&gt;
Lunghezza dell&#39;array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var len =&amp;nbsp;arr.length;&lt;/span&gt;&lt;br /&gt;
Ciclare un array;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;arr.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var v = arr[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Unire due array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr = [10, &quot;test&quot;, false];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr2 = [2, true, &quot;test2&quot;];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;arr.concat( arr2 ); &amp;nbsp;// arr =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;[10, &quot;test&quot;, false,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;2, true, &quot;test2&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
Trasformare un array in una stringa:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = arr.join(&quot;,&quot;); &amp;nbsp; &lt;i&gt;// s = &quot;10,test,false&quot;;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Rimuovere l&#39;ultimo elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;arr.pop(); &amp;nbsp;&lt;i&gt;// arr = [10,&quot;test&quot;]&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Aggiungere un nuovo elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;arr.push(&quot;new item&quot;);&lt;/span&gt;&lt;br /&gt;
Invertire l&#39;ordine degli elementi&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;arr.reverse(); &amp;nbsp; &amp;nbsp;&lt;i&gt;// arr = [true, &quot;test&quot;, 10]&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Rimuovere il primo elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;arr.shift() ; &amp;nbsp; &amp;nbsp; &lt;i&gt;// arr = [&quot;test&quot;, 10]&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Per aggiungere un elemento all&#39;inizio:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: normal;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.unshift(&quot;new item&quot;);   &lt;i&gt;// &lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;&lt;i&gt;a = [&quot;new item&quot;, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Ottenere una parte di array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr2 = arr.slice(0,1); &amp;nbsp; &lt;i&gt;// arr2 = [10, &quot;test&quot;]&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Ordinare un array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;var a = [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.sort();   &lt;i&gt;// a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Ordimento personalizzato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;var a = [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;a.sort(function(val1, val2) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;    if( myCondition ) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;        return true;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;    }else {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;        return false;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Inserire un nuovo elemento:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.splice(1,0, &quot;new Item&quot;) ;    /&lt;i&gt;/  a = &lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;i&gt;[&lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;b&lt;/span&gt;&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;new Item&lt;/span&gt;&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;c&lt;/span&gt;&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;d&lt;/span&gt;&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;a&lt;/span&gt;&quot;&lt;/span&gt;]&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;il primo argomento indica la posizione, il secondo indica quanti  evetuali elementi sostituire, il terzo indica il valore dell&#39;elemento da inserire/sostituire.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Si possono specificare più valori:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;];&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.splice( 1,0 &quot;1&quot;,&quot;2&quot;,&quot;3&quot;);   &lt;i&gt;// a = [&quot;a&quot;, &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Sostituire un elemento:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.splice(1,1, &quot;new Item&quot;) ;    &lt;i&gt;//  a = &lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;i&gt;[&lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;a&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;&lt;span class=&quot;console-formatted-string source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;new Item&lt;/span&gt;&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;c&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;d&quot;&lt;/span&gt;]&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Questa funzione è utile anche per rimuovere un valore in una data posizione, è sufficiente non specificare il terzo argomento:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;a.splice(1,1) ;    &lt;i&gt;//  a = &lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;i&gt;[&lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;a&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;c&quot;&lt;/span&gt;, &lt;span class=&quot;source-code&quot; style=&quot;box-sizing: border-box; white-space: pre-wrap;&quot;&gt;&quot;d&quot;&lt;/span&gt;]&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Per rimuovere un elemento in base al suo valore occorre ciclare l&#39;array:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;var itemToRemove = &quot;b&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;var a = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;for(var i=0;i&amp;lt;a.length;i++){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;   if( a[i]==itemToRemove )&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;       a.splice(i,1);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Date&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
L&#39;oggetto &quot;date&quot; viene così creato:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d = new Date();&lt;/span&gt;&lt;br /&gt;
l&#39;oggetto che abbiamo creato si riferisce alla data corrente.&lt;br /&gt;
Per creare un oggetto che si riferisca ad una determinata data passiamo anno, mese e giorno nel costruttore:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d = new Date(1973,8,20);&lt;/span&gt;&lt;br /&gt;
la data si riferisce al giorno 20 settembre 1973 (il mese può essere un valore compreso tra 0, gennaio, e 11, dicembre).&lt;br /&gt;
Ovviamente possiamo specificare anche ora e minuti.&lt;br /&gt;
Se nel costruttore specifichiamo un solo argomento, viene interpretato come millisencondi a partire dal 1 gennaio 1970.&lt;br /&gt;
Gli oggetti &quot;date&quot; possono essere confrontati per esempio per determinare se una data è maggiore di un&#39;altra:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d1 = new Date(); // now&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d2 = new Date(2011,0,20); &lt;i&gt;// 20 gennaio 2011&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if(d2&amp;gt;d1){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; //...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Tuttavia non possiamo verificare direttamente se due date sono uguali:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d1 = new Date(2011,0,20);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d2 = new Date(2011,0,20);&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if(d1==d2){ ...&amp;nbsp;}else{ ...} //&lt;i&gt; NON FUNZIONA!&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Occorre utilizzare il metodo &quot;getTime()&quot; (restituisce la data &amp;nbsp;in millisecondi):&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if( d1.getTime()==d2.getTime() )...&lt;/span&gt;&lt;br /&gt;
E&#39; possibile effettuare operazioni come per esempio la differenza tra due date:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var diff = d1-d2;&lt;/span&gt;&lt;br /&gt;
il risultato è un numero che rappresenta la differenza in millisecondi da cui possiamo ricavarci l&#39;equivalente in altre unità di misura:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var seconds = diff / 1000; // &lt;i&gt;differenza in secondi&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var minutes = seconds / 60; /&lt;i&gt;/differenza in minuti&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var hours = minutes / 60; //&lt;i&gt;differenza in ore&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
L&#39;oggetto date è fornito di diversi metodi per ottenere (metodi get) o assegnare (metodi set) elementi della data:&lt;br /&gt;
giorno del mese (1-31)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getDate() setDate()&lt;/span&gt;&lt;br /&gt;
giorno della settimana (0-6)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getDay()&lt;/span&gt;&lt;br /&gt;
mese (0-11)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getMonth(), setMonth()&lt;/span&gt;&lt;br /&gt;
anno (4 cifre)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getFullYear(), setFullYear();&lt;/span&gt;&lt;br /&gt;
ore (0-23)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getHours(), setHours()&lt;/span&gt;&lt;br /&gt;
minuti(0-59)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getMinutes(), setMinutes();&lt;/span&gt;&lt;br /&gt;
secondi (0-59)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getSeconds(), setSeconds();&lt;/span&gt;&lt;br /&gt;
millisecondi (0-999)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getMilliseconds(), setMilliseconds();&lt;/span&gt;&lt;br /&gt;
data in millisecondi (a partire da 1/1/1970)&lt;span style=&quot;color: #cc0000;&quot;&gt;: getTime(), setTime()&lt;/span&gt;&lt;br /&gt;
Se assegniamo a più variabili lo stesso oggetto data:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d1 = new Date(2011,8,20); // 20 settembre 2011&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d2 = d1;&amp;nbsp;&lt;i&gt;// 20 settembre 2011&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d3 = d1;&lt;i&gt;&amp;nbsp;// 20 settembre 2011&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
stiamo passando il riferimento di uno stesso oggetto data, quindi se modifichiamo uno dei valori, come risultato otterremo una modifica su tutte le variabili:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;d3.setFullYear(1973);&lt;i&gt; //20 settembre 1973&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;//d2 -&amp;gt;&amp;nbsp;20 settembre 1973&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;//d1 -&amp;gt;&amp;nbsp;20 settembre 1973&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Per duplicare (clonare) una data occorre istanziare un nuovo oggetto date:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d1 = new Date(2011,8,20);&lt;i&gt; // 20 settembre 2011&lt;/i&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d2 = new Date( d1.getTime() );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var d3 = new Date( d1.getTime() );&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esempio: calcolo dell&#39;età in anni in base alla sua data di nascita&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var birthDate = new Date(1973, 8, 20);&amp;nbsp;&lt;i&gt;&amp;nbsp; &amp;nbsp;// 20 settembre 1973&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var today = new Date();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var age = today.getFullYear() - birthDate.&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;getFullYear();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if( birthDate.getMonth()&amp;gt;today.getMonth() &amp;nbsp;|| &amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;birthDate.getMonth()==today.getMonth() &amp;amp;&amp;amp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;birthDate.getDate()&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;today.&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;getDate&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;)){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; age--;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
Esempio: fare il parsing di una stringa e creare il relativo oggetto date:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var regExp =&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #cc0000; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; text-align: -webkit-auto; white-space: pre-wrap;&quot;&gt;/^(\d{2})\/(\d{2})\/(\d{4})$/&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; text-align: -webkit-auto; white-space: pre-wrap;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var s = prompt(&quot;inserisci la tua data di nascita (dd/mm/yyyy)&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var parsedDate = s.match(regExp);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if(parsedDate) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var day =&amp;nbsp;parsedDate[1], month=parsedDate[2], year=parsedDate[3]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var birthDate = new Date(year,month,day);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;formato data invalido&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #cc0000; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; text-align: -webkit-auto; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #cc0000; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; text-align: -webkit-auto; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;u&gt;&lt;b&gt;&lt;i&gt;Funzione void&lt;/i&gt;&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La funzione&amp;nbsp;&lt;i&gt;void&lt;/i&gt;&amp;nbsp;è una funzione che restituisce&amp;nbsp;&lt;i&gt;undefined&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Se per esempio definiamo una funzione:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function doFoo() {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(&quot;foo&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return false;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = void( doFoo() );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
il valore di &quot;&lt;i&gt;a&lt;/i&gt;&quot; sarà&amp;nbsp;&lt;i&gt;undefined&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Tipicamente si utilizza questa funzione sul tag HTML &amp;lt;a&amp;gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Questo tag normalmente viene utilizzato per caricare una pagina o andare su un determinato punto della pagina.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Per evitare il ricaricamento della pagina si utilizzata la funzione&amp;nbsp;&lt;i&gt;void&lt;/i&gt;&amp;nbsp;nell&#39;attributo &quot;&lt;i&gt;href&lt;/i&gt;&quot;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;a href=&quot;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;javascript:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;void(0)&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot; onclick=&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(&#39;clicked&#39;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot; &amp;gt;click me&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
equivalente a :&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;a href=&quot;&lt;b&gt;#&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot; onclick=&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(&#39;clicked&#39;);return false;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot; &amp;gt;click me&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Funzioni Timer&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Javascript consente di eseguire delle instruzioni in maniera &quot;temporizzata&quot; tramite delle funzioni dell&#39;oggetto &quot;window&quot;.&lt;br /&gt;
Le funzioni che permettono di fare questo sono:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;setTimeout &lt;/span&gt;(esegue una funzione dopo un tempo specificato e restituisce un id di riferimento)&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;setInterval &lt;/span&gt;(esegue una funzione a intervalli di tempo regolari e restituisce un id di riferimento)&lt;br /&gt;
(nota: sono metodi dell&#39;oggetto window: window.setTimeout e window.setInterval)&lt;br /&gt;
e i rispettivi metodi che ne bloccano l&#39;esecuzione:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;clearTimeout()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;cleartInterval()&lt;/span&gt;&lt;br /&gt;
Nel esempio seguente viene mostrato un un messaggio dopo un secondo (l&#39;intervallo specificando è un millisecondi):&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;setTimeout&lt;/b&gt;(function(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(&quot;Hello&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}, 1000);&lt;/span&gt;&lt;br /&gt;
oppure:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;function alertHello(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;alert(&quot;Hello&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;setTimeout&lt;/b&gt;(alertHello, 1000);&lt;/span&gt;&lt;br /&gt;
In questo altro esempio invece visualizziamo un semplice cronometro (si presuppone l&#39;esistenza nella pagina di un div con id = &quot;cron&quot; e di pulsanti &quot;button&quot; start, stop, reset):&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;div id=&quot;cron&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;button onclick=&quot;startCron()&quot;&amp;gt;start&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;button onclick=&quot;stopCron()&quot;&amp;gt;stop&amp;lt;/button&amp;gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;button onclick=&quot;resetCron()&quot;&amp;gt;reset&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var cron = 0,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;t = null, cronEl =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;cron&quot;)&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;function startCron(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; if(t!=null)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;stopCron();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; t = &lt;b&gt;setInterval&lt;/b&gt;( function(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;cronEl&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;.innerHTML = ++cron;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }, 100); //0.1 sec&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;function stopCron(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(t) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;clearInterval&lt;/b&gt;(t);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t = null;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;function resetCron(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;cron = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;cronEl&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;.innerHTML = cron;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Funzioni globali di javascript&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In questo e nel precedente tutorial sono stati già utilizzate alcune funzioni come &quot;alert&quot;, &quot;isNaN&quot;, &quot;setTimout&quot;.&lt;br /&gt;
Alcune di queste appartengono all&#39;oggetto window (es.&quot;alert&quot; che può essere invocando scrivendo &quot;window.alert&quot;), altre invece sono funzioni globali.&lt;br /&gt;
Seguono le altre funzioni globali:&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;parteInt, parseFloat&lt;/u&gt;&lt;br /&gt;
La funzione &quot;parseInt&quot; cerca di estrarre da una stringa un numero intero. Prevede due argomenti: la stringa da parsare e la base numerica (opzionale, ma consiglio sempre di specificarla, normalmente si specifica 10).&lt;br /&gt;
esempio:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var n = &lt;b&gt;parseInt&lt;/b&gt;(&quot;09&quot;,10); //n=9&lt;/span&gt;&lt;br /&gt;
Se dalla stringa non è possibile estrarre un numero, viene restituito NaN (Not a number).&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var n = &lt;b&gt;parseInt&lt;/b&gt;(&quot;sdfsdfs&quot;); &lt;i&gt;//n=NaN&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Una stringa può anche contenere solo nella parte iniziale un numero:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var n = &lt;b&gt;parseInt&lt;/b&gt;(&quot; 10 oggetti &quot;); //n = 10&lt;/span&gt;&lt;br /&gt;
La funzione &quot;parseFloat&quot; rispetto a &quot;parseInt&quot; cerca di estrarre un numero con virgola (il punto viene riconosciuto come separatore decimale).&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;escape, unescape&lt;/u&gt;&lt;br /&gt;
Queste funzioni rispettivamente codificano e decodificano i caratteri speciali:&lt;br /&gt;
Esempio:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var escaped = &lt;b&gt;escape&lt;/b&gt;(&quot;test*?&amp;amp;&quot;); &lt;i&gt;//escaped=&quot;test*%3F%26&quot;&lt;/i&gt;&lt;br /&gt;var unescaped = &lt;b&gt;unescape&lt;/b&gt;(escaped);&lt;i&gt; //unescaped=&quot;test*?&amp;amp;&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;color: #0080ff; font-family: Consolas, &#39;Lucida Console&#39;, monospace;&quot;&gt;&lt;span style=&quot;font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;u&gt;eval&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Questa funzione legge il contenuto di una stringa e li interpreta come codice javascript:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Per esempio:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;eval&lt;/b&gt;(&quot;alert(&#39;test&#39;)&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
l&#39;effetto di questa istruzione quindi sarà quello di mostrare una finestra di alert.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
L&#39;uso di questa funzione è sconsigliato, in quanto esegue codice a runtime, cioè senza precompilazione da parte del browser. Quindi il risultato sarebbe un peggioramento delle prestazioni di esecuzione ed eventualmente una maggiore difficoltà di individuare errori in fase di debugging.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Normalmente viene utilizzata per &quot;parsare&quot; il contenuto json di una risposta ajax:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var json = &quot;{&#39;prop1&#39;:44,&#39;prop2&#39; : &#39;test&#39;}&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var obj = &lt;b&gt;eval&lt;/b&gt;( &quot;(&quot; + json + &quot;)&quot; );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;alert( obj.prop1 );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;alert( obj.prop2 );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/4653008414149012151/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4653008414149012151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4653008414149012151'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html' title='Javascript le basi (2a parte)'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-455004036421596068</id><published>2011-07-03T14:52:00.090+02:00</published><updated>2014-05-17T19:55:40.363+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>Javascript le basi (1a parte)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html&amp;amp;sl=it&amp;amp;tl=en&amp;amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;Indice dei tutorials:&amp;nbsp;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Prima di iniziare&lt;/span&gt;&lt;br /&gt;
Negli esempi che seguono, verrà spesso utilizzata l&#39;istruzione &amp;nbsp;&quot;alert()&quot;. Questa funzione mostra una finestra con un messaggio.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Dove scrivere codice javascript.&lt;/span&gt;&lt;br /&gt;
Come gia probabilmente saprete la struttura base di una pagina HTML è la seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
Ci sono diversi posti dove inserire codice javascript:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1.&lt;/b&gt; all&#39;interno del tag &amp;lt;script&amp;gt;:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/div&gt;
Normalmente si inseririsce il tag &amp;lt;script&amp;gt; all&#39;interno del &amp;lt;&lt;i&gt;head&amp;gt;&lt;/i&gt;, ma è possibile inserirlo anche all&#39;interno del &amp;lt;body&amp;gt;.&lt;br /&gt;
Nella fase di caricamento della pagina, il browser interpreta ed ed esegue immediatamente il codice &amp;nbsp;javascript all&#39;interno del tag &amp;lt;script&amp;gt; appena caricato.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.&lt;/b&gt; all&#39;interno di un attributo evento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;button onclick=&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(&quot;hello world&quot;);&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot; &amp;gt;click me&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
Il codice in questo caso viene eseguito sul click del pulsante.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3.&lt;/b&gt; in un file dedicato con estensione &lt;i&gt;.js&lt;/i&gt;; in questo file non occorre racchiudere il codice nel tag &lt;i&gt;&amp;lt;script&amp;gt;&lt;/i&gt;; per caricare il file nella pagina &lt;i&gt;html&lt;/i&gt; aggiungere il seguente codice (preferibilmente all&#39;interno del tag &lt;i&gt;&amp;lt;head&amp;gt;&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;script src=&quot;&lt;b&gt;myscript.js&lt;/b&gt;&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
nell&#39;attributo &lt;i&gt;src&lt;/i&gt; si specifica il nome del file con eventuale percorso (es: /js/myscript.js)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4.&lt;/b&gt; all&#39;interno dell&#39;attributo &lt;i&gt;href&lt;/i&gt; del tag &lt;i&gt;&amp;lt;a&amp;gt;&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;a href=&quot;javascript:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(\&quot;hell world\&quot;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot;&amp;gt;my link&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;
aggiungendo quindi il prefisso &quot;javascript:&quot;. Il codice viene eseguito sul click del link.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;i&gt;Nota&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
Nella barra degli indirizzi è possibile scrivere codice javascript (per esempio per fare un debug), basta aggiungere il prefisso &quot;javascript:&quot; come per l&#39;attributo href.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Sintassi di base&lt;/span&gt;&lt;br /&gt;
Le istruzioni javascript sono separatate dal punto e virgola &quot;;&quot;. E&#39; possible inserire più istruzioni su una riga, purchè separate da &quot;;&quot;:&lt;br /&gt;
&lt;i&gt;istruzione1&lt;/i&gt;; &lt;i&gt;istruzione2&lt;/i&gt;;&lt;br /&gt;
Con le parentesi graffe si definiscono un gruppo di istruzioni (usate per cicli &amp;nbsp;funzioni):&lt;br /&gt;
{&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; istruzione1&lt;/i&gt;;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; istruzione2&lt;/i&gt;;&lt;/div&gt;
}&lt;br /&gt;
Le parentesi graffe si utilizzano anche per definire proprietà e metodi di un oggetto:&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; prop1: 10,&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; prop2: 20,&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; method1: function() { &amp;nbsp;istruzioni }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Per inserire commenti su una sola riga si usa il il&amp;nbsp;doppio slash (//)&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;// &lt;i&gt;my comment&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
E&#39; possibile inserire un commento sulla stessa riga dopo un istruzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;istruzione1; //&lt;i&gt;comment&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
I commenti su più righe si riacchiudono tra i caratteri &amp;nbsp;di apertura /* e di chiusura */:&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;my comment&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;...&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;*/&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Variabili e assegnazione&lt;/span&gt;&lt;br /&gt;
In javascript le variabili si dichiarano con &quot;&lt;i&gt;var&quot;&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a;&lt;/span&gt;&lt;br /&gt;
Per assegnare un valore si usa &quot;=&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a = 5;&lt;/span&gt;&lt;br /&gt;
finché non assegniamo un valore alla nostra variabile, essa è &lt;i&gt;undefined&lt;/i&gt;&lt;i&gt;.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
Questo non significa che la variabile non è definita, ma che il suo valore non è definito.&lt;br /&gt;
Per chiarire questo concetto pensiamo ad una variabile come ad una scatola.&lt;br /&gt;
Quando dichiariamo una variabile, predisponiamo una scatola vuota con su stampato il suo nome (es.&#39;a&#39;).&lt;br /&gt;
Se non la dichiariamo &amp;nbsp;e la usiamo nel codice, questo genera un errore perché il browser non trova la scatola nel magazzino delle variabili (tecnicamente nella memoria del computer).&lt;br /&gt;
Assegnando un valore alla variabile, la &quot;scatola&quot; viene riempita con qualcosa. Con l&#39;istruzione &lt;span style=&quot;color: #cc0000;&quot;&gt;a = 5&lt;/span&gt; abbiamo riempito la scatola con un numero intero. Possiamo successivamente riempirla con qualcos&#39;altro, per esempio con una stringa (sequenza di caratteri):&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;a = &quot;ciao&quot;;&lt;/span&gt;&lt;br /&gt;
Questo ci fa capire che la stessa scatola può contenere qualsiasi cosa sia definibile in javascript come numeri, stringhe, funzioni e oggetti. L&#39;oggetto è una specie di set di scatole, quindi la nostra variabile &quot;scatola&quot; può contenere a sua volta altre scatole.&lt;br /&gt;
Con la parola chiave &quot;undefined&quot;, il browser ci comunica che la scatola è vuota, non contiene niente. Però occupa spazio nel nostro magazzino. Sarà bene riempirla per non sprecare spazio e quindi rendere più efficiente il notro codice.&lt;br /&gt;
Possiamo svuotare la &quot;scatola&quot; in questo modo:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;a = undefined;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Possiamo dichiarare una variabile e assegnargli un valore in un&#39;unica istruzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 5;&lt;/span&gt;&lt;br /&gt;
possiamo dichiarare più variabili separandole con la virgola:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a,b;&lt;/span&gt;&lt;br /&gt;
e pure inizializzarle:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 5, b = &quot;ciao&quot;, c;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Non viene sollevato errore javascript se dichiariamo più volte la stessa variabile:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 5;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = &quot;Hello world&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Se una variabile viene dichiarata una seconda volta senza assegnarne un valore, non perde il suo valore precedente:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 5;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a; &amp;nbsp;&amp;nbsp;&lt;i&gt;// a = 5&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
Anche se può sembrare senza senso, in certi casi dichiarare una seconda volta la variabile ha lo scopo di assicurarci l&#39;esistenza della &quot;scatola&quot; nel magazzino delle variabili. Sarà più chiaro più avanti.&lt;br /&gt;
&lt;br /&gt;
Con &quot;&lt;i&gt;var&lt;/i&gt;&quot; non possiamo definirne il tipo (javascript non è un linguaggio tipizzato); il tipo dipende dal valore che le è stato assegnato (la scatola può essere riempita con vari tipi di cose):&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var myString = &quot;Hello world&quot;; &lt;i&gt;// string&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var myString2 = new String(&quot;Hello world 2&quot;); / / &lt;i&gt;string&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 0; &amp;nbsp; &lt;i&gt;//number&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var status = true &lt;i&gt;//boolean&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr = [1, 4, 4]; &lt;i&gt;//array&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var myDate = new Date(); &amp;nbsp;&lt;i&gt;//object&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;Stringhe&lt;/span&gt;&lt;br /&gt;
Una sequenza di caratteri che definisce una stringa, può essere delimitata da doppie virgolette o singoli apici:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Hello World&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = &#39;Hello world 2&#39;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Possiamo inserire apici delimitati da doppie virgolette o viceversa:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var s1 = &quot; Hello &#39; World &#39; &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var s2 = &#39; Hello &quot; World &quot; &amp;nbsp;&#39;;&lt;/span&gt;&lt;br /&gt;
Esistono caratteri speciali che possono essere inseriti tramite il carattere backslash:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var s = &quot; doppie virgolette: &lt;span style=&quot;background-color: yellow;&quot;&gt;\&quot;&lt;/span&gt; &amp;nbsp;backslash: &lt;b style=&quot;background-color: yellow;&quot;&gt;\\&lt;/b&gt; &amp;nbsp;ritorno a capo &lt;span style=&quot;background-color: yellow;&quot;&gt;\n&lt;/span&gt; &amp;nbsp;tabulazione: &lt;span style=&quot;background-color: yellow;&quot;&gt;\t&lt;/span&gt;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;Array&lt;/span&gt;&lt;br /&gt;
Gli array sono una lista di cose come numeri,stringhe,etc.&lt;br /&gt;
Un array è come una scatola che contiene al suo interno varie scatole numerate a partire da zero &quot;&#39;0&quot;.&lt;br /&gt;
Per definire un array si usano le parentesi quadre:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var a = [];&lt;/span&gt;&lt;br /&gt;
Questo è un array vuoto. Si riempe con questa sintassi:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;a[0] = &quot;ciao&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;a[1] = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;a[2] = 21.43;&lt;/span&gt;&lt;br /&gt;
Oppure:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var a = [&quot;ciao&quot;, 10, 21.43];&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Come potete constatare, i vari elementi dell&#39;array sono eterogenei, cioè non devono essere necessariamente dello stesso tipo. Nell&#39;esempio ll primo elemento è una stringa (elemento 0), il secondo un numero (elemento 1).&lt;br /&gt;
&lt;br /&gt;
Si può accendere quindi al valore di uno degli elementi tramite l&#39;indice numerico:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var b = a[1];&lt;/span&gt;&lt;br /&gt;
Attenzione, se usate un indice superiore alla dimensione dell&#39;array, viene generato un errore javascript.&lt;br /&gt;
Per sapere quanti elementi ha un array, si usa la proprietà &quot;length&quot;:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var lunghezzaArray = a.length;&lt;/span&gt;&lt;br /&gt;
Avendo il primo elemento indice 0, per accedere all&#39;ultimo elemento:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var b = a[a.length-1];&lt;/span&gt;&lt;br /&gt;
L&#39;array che abbiamo creato in linguaggio matematico sarebbe definito &quot;vettore&quot;, cioè è un array monodimensionale. Ogni elemento è uno scalare.&lt;br /&gt;
E&#39; possibile creare array multidimensionali (matrici):&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var m = [ ];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;m[0] = [255,&quot;hello&quot;]; // prima riga&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;m[1] = [&quot;ciao&quot;, 10.23]; // seconda riga&lt;/span&gt;&lt;br /&gt;
Questa è una matrice bidimensionale 2x2, ogni riga è un vettore.&lt;br /&gt;
Per accedere ad uno degli elementi di questa matrice:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var b = m[1,0]; //seconda riga, prima colonna &quot;ciao&quot;&lt;/span&gt;&lt;br /&gt;
Per saperne di più, date un&#39;occhiata al tutorial:&amp;nbsp;&lt;i&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;Oggetti&lt;/span&gt;&lt;br /&gt;
Nella nostra analogia con le scatole, abbiamo descritto gli oggetti come un set di scatole che a loro volta possono contenere altre cose tipo numeri, stringhe, funzioni, array e altri oggetti.&lt;br /&gt;
Quindi è molto simile ad un array, ma con la differenza che le scatole che contiene, non sono numerate, ma etichettate con dei nomi come negli array associativi di certi linguaggi.&lt;br /&gt;
Un oggetto può essere creato in questa maniera:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var a = {saluto: &quot;ciao&quot;, numero:10 };&lt;/span&gt;&lt;br /&gt;
Per accedere alle variabili &amp;nbsp;dell&#39;oggetto&amp;nbsp;(il nome tecnico è proprietà), si usa il carattere punto &quot;.&quot;:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;alert( a.saluto );&lt;/span&gt;&lt;br /&gt;
Alternativamente si può accedere alla proprietà di un oggetto tramite le parentesi quadre:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;alert( a[&quot;saluto&quot;] );&lt;/span&gt;&lt;br /&gt;
Per saperne di più date un occhiata al seguente tutorial:&lt;br /&gt;
&lt;i&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
vi consiglio però di finire di leggere questo tutorial.&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Typeof&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;E&#39; possible verificare il tipo di un valore di una variabile tramite la funzione&amp;nbsp;&lt;i&gt;typeof&lt;/i&gt;&lt;i&gt;:&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var type = typeof(a);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;i valori possibili restituiti sono le seguenti stringhe:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, helvetica, sans-serif; font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;color: black; margin-bottom: 9px; margin-top: 1px;&quot;&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&quot;number&quot;&lt;/span&gt;&lt;/li&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&quot;string&quot;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&quot;boolean&quot;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&quot;object&quot;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&quot;function&quot;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 2px;&quot;&gt;&quot;undefined&quot;&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;Una sintassi alternativa di &lt;i&gt;typeof&lt;/i&gt; è:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var type =&amp;nbsp;&lt;b&gt;typeof&lt;/b&gt;&amp;nbsp;myVar;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Quindi questa istruzione non dice cosa contiene la nostra scatola, ma di che tipo è (un numero, una stringa, etc).&lt;br /&gt;
Notate che il tipo &quot;number&quot; indica sia numeri interi (integer) che numeri con la virgola (float).&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Operazioni&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Abbiamo visto in precedenza l&#39;operatore di assegnamento &quot;=&quot;. Ne esistono altri:&lt;br /&gt;
+= &lt;i&gt;concatena&lt;/i&gt;/&lt;i&gt;somma al valore attuale&lt;/i&gt;&lt;br /&gt;
-= &amp;nbsp;&lt;i&gt;sottrai al valore attuale&lt;/i&gt;&lt;br /&gt;
/= &lt;i&gt;dividi al valore attuale&lt;/i&gt;&lt;br /&gt;
*= &lt;i&gt;moltiplica al valore attuale&lt;/i&gt;&lt;br /&gt;
Esempi:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = 10&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;c += 5; &amp;nbsp; // &lt;i&gt;c = 15&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;c -= 2; &amp;nbsp; &amp;nbsp;// &lt;i&gt;c = 13&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I simboli degli operatori aritmetici sono:&lt;br /&gt;
+ &lt;i&gt;addizione&lt;/i&gt;&lt;br /&gt;
- &lt;i&gt;sottrazione&lt;/i&gt;&lt;br /&gt;
* &lt;i&gt;moltiplicazione&lt;/i&gt;&lt;br /&gt;
% &lt;i&gt;modulo&lt;/i&gt;&lt;br /&gt;
Quindi possiamo assegnare ad una variabile il risultato di un&#39;operazione matematica:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 5;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = a * b;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;Le parentesi tonde sono utilizzate per raggruppare operazioni da eseguire in ordine prioritario:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = a * b &amp;nbsp;* (a + b);&lt;/span&gt;&lt;br /&gt;
Il simbolo % calcola il resto di una divisione tra due numeri. Esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = 10 % 5; &amp;nbsp; // &lt;i&gt;c =0&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = 10 % 3; &amp;nbsp; // &lt;i&gt;c = 1&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Per concatenare più stringhe si utilizza sempre il simbolo &quot;+&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Hello&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s2 = s+&quot; world!&quot;;&lt;/span&gt;&lt;br /&gt;
Usando l&#39;operatore &quot;+&quot; tra stringhe e numeri, otteniamo sempre una stringa, il numero viene convertito in stringa e poi concatenato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;il numero è &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var message = s+n; &amp;nbsp;&lt;i&gt;// = &quot;il numero è 10&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In javascript i tipi sono &amp;nbsp;automaticamente convertiti nel tipo più adatto:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;10&quot;; // &lt;i&gt;string&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = s * 5; //&lt;i&gt; n = 50&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
la variabile stringa &quot;s&quot; viene convertita in un numero, perché in una moltiplicazione il simbolo di moltiplicazione può essere usato solo tra numeri.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La stringa vuota viene convertita in 0:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 10 *s; // n = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Anche i valori&amp;nbsp;&lt;i&gt;null&lt;/i&gt;&amp;nbsp;(un parola chiave spiegata più avanti) e&amp;nbsp;&lt;i&gt;undefined&lt;/i&gt;&amp;nbsp;sono convertiti nel valore numerico&amp;nbsp;&lt;i&gt;zero&lt;/i&gt;.&lt;/div&gt;
&lt;br /&gt;
Se la stringa non rappresenta un numero, il risultato aritmetico è &quot;&lt;i&gt;NaN&lt;/i&gt;&quot; (è una parola chiave che significa &lt;i&gt;Not a Number&lt;/i&gt;, non è un numero):&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;text&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 10 * s; &amp;nbsp;// n = NaN&lt;/span&gt;&lt;br /&gt;
il valore di &quot;s&quot;, non essendo convertibile in numero, moltiplicato per un numero genera un valore di tipo numero non rappresentabile. Sulla scatola c&#39;è stampato oltre al nome &quot;n&quot;, anche il tipo &quot;number&quot;, ma la scatola è vuota. Un modo javascript di comunicare che c&#39;è stato un errore dell&#39;operazione, senza sollevare errori.&lt;br /&gt;
&lt;br /&gt;
Come già visto, il simbolo &quot;+&quot; può concatenare stringhe o sommare numeri. Se uno dei valori è una stringa, l&#39;operazione effettuata è quella di concatenazione, anche se simbolicamente la variabile di tipo stringa contiene un numero:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;10&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = s + 5; &amp;nbsp;// &lt;i&gt;s = 105&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Come nel linguaggio &quot;c&quot; o &quot;java&quot;, è possibile utilizzare gli operatori di incremento:&lt;br /&gt;
++ &lt;i&gt;incrementa di 1&lt;/i&gt;&lt;br /&gt;
-- &lt;i&gt;decrementa di 1&lt;/i&gt;&lt;br /&gt;
Esempi:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a += 3; &amp;nbsp; // &lt;i&gt;a = 13&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a -= 5; &amp;nbsp;// &lt;i&gt;a = 8;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;Hello&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;s += &quot; World&quot;; &amp;nbsp; //&lt;i&gt; s = &quot;Hello World&quot;&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var m = 5;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = m++; &amp;nbsp; // &lt;i&gt;n = 5, m = 6&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;m = 5;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = ++m &amp;nbsp; // &lt;i&gt;n = 6, &amp;nbsp;m = 6&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;i&gt;&lt;b&gt;Funzioni matematiche&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
Oltre alle operazioni aritmentiche, in javascript è possibile effettuare operazioni trigonometriche, logaritmiche, etc utilizzando l&#39;oggetto &lt;i&gt;Math. &lt;/i&gt;L&#39;elenco dell&#39;operazioni è elencato nella seconda parte di questo tutorial:&lt;br /&gt;
&lt;i&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&lt;u&gt;Infinito&lt;/u&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Come si è gia accennato in precedenza, javascript gestisce certe anomalie &amp;nbsp;usando parole chiavi.&lt;br /&gt;
Abbiamo visto &quot;NaN&quot; (Not a Number).&lt;br /&gt;
Un altro valore particolare è &lt;i&gt;Infinity &lt;/i&gt;(infinito). Javascript è in grado di riempire una scatola di &quot;infinito&quot;, cioè un valore così grande da non poter essere rappresentato.&lt;br /&gt;
Questo ci suggerisce che &lt;i&gt;Infinity&lt;/i&gt;&amp;nbsp;per javascript viene considerato un numero a tutti gli effetti che può essere utilizzato nelle normali operazioni matematiche.&lt;br /&gt;
&lt;br /&gt;
Questo valore viene assegnato quando il valore numerico oltrepassa i seguenti limiti:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 12px;&quot;&gt;Infinity &amp;gt; 1.7976931348623157E+10308&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-decorations-in-effect: initial; font-family: verdana, helvetica, arial, sans-serif; font-size: 12px; font-style: normal;&quot;&gt;-Infinity &amp;lt; -1.7976931348623157E+10308&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
quindi, la differenza con il concetto matematico a cui si attribuisce il numero infinito come un numero maggiore di qualsiasi numero finito, sta proprio nel limite massimo&amp;nbsp;fisico previsto per i valori numerici finiti in javascript oltre il quale appunto i numeri non sono rappresentabili.&lt;br /&gt;
&lt;br /&gt;
Quindi, se dividiamo un numero per &lt;i&gt;zero&lt;/i&gt;, javascript non solleva un errore come in altri linguaggi, ma restituisce il valore di tipo numero &quot;&lt;i&gt;Infinity&lt;/i&gt;&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 10 / 0; &amp;nbsp; &amp;nbsp;// &lt;i&gt;n = Infinity&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Ecco cosa succede operando con questo valore:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = &lt;b&gt;Infinity&lt;/b&gt; - &lt;b&gt;Infinity&lt;/b&gt;; &amp;nbsp; //&lt;i&gt; n = NaN&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n = 19 / &lt;b&gt;Infinity&lt;/b&gt;; &amp;nbsp; //&lt;i&gt; n = 0&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Incrementando, dividendo, moltiplicando o dividendo &lt;i&gt;Infinity&lt;/i&gt; per qualsiasi numero otteniamo sempre un valore &lt;i&gt;Infinity&lt;/i&gt;:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var n = 23 +&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #cc0000;&quot;&gt;Infinity&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;; &amp;nbsp; //&lt;/span&gt;&lt;i style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;n =&amp;nbsp;&lt;/i&gt;&lt;i style=&quot;color: #cc0000;&quot;&gt;Infinity&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Valori speciali&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Esistono tre valori particolari da tenere in considerazione:&lt;br /&gt;
-&amp;nbsp;&lt;i&gt;undefined&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;- NaN&amp;nbsp;&lt;/i&gt;&lt;i&gt;(Not a Number)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;-&amp;nbsp;&lt;/i&gt;&lt;i&gt;null&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Precedentemente abbiamo visto il valore &quot;&lt;i&gt;undefined&lt;/i&gt;&quot;, che come è stato gia detto, è il valore di default assegnato ad una variabile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(a) ); // &lt;i&gt;show &quot;undefined&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Ma se ci riferiamo ad una variabile mai dichiarata, otteniamo un errore javascript:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(b) );&amp;nbsp;// &lt;i&gt;questo genera un errore javascript perchè la variabile non è mai stata dichiarata&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
In sostanza se dichiariamo una variabile senza inizializzarla, il suo valore di default è &quot;&lt;i&gt;undefined&lt;/i&gt;&quot;, quindi &amp;nbsp;l&#39;istruzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a;&lt;/span&gt;&lt;br /&gt;
è equivalente alla seguente assegnazione :&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = &lt;i&gt;undefined&lt;/i&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Il valore di una &amp;nbsp;variabile può essere&amp;nbsp;&lt;i&gt;NaN&amp;nbsp;&lt;/i&gt;&lt;i&gt;(Not a Number)&lt;/i&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&amp;nbsp;se il tipo della variabile è &quot;&lt;i&gt;number&lt;/i&gt;&quot;. Abbiamo già accennato &amp;nbsp;precedentemente ad alcuni casi in cui si ottiene &lt;i&gt;NaN&lt;/i&gt;.&lt;br /&gt;
Ecco altri casi in cui una variabile può essere &lt;i&gt;NaN&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a++;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(a) ); &amp;nbsp;//&lt;i&gt;show &quot;number&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( a ); &amp;nbsp;//&lt;i&gt;show NaN&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
qualsiasi operazione matematica con un &lt;i&gt;NaN&lt;/i&gt; restituisce sempre un &lt;i&gt;NaN&lt;/i&gt;.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = a + b // &lt;i&gt;c = NaN&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Esistono delle funzione javascript che restituiscono &lt;i&gt;NaN&lt;/i&gt;, per esempio la funzione &lt;i&gt;parseInt&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n1 = parseInt(&quot;22&quot;); &amp;nbsp; //&lt;i&gt; n1 = 22;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var n2 = parseInt(&quot;Hello world&quot;); &amp;nbsp; //&amp;nbsp;&lt;i&gt;n2 = NaN;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
nota: &lt;i&gt;parseInt &lt;/i&gt;è una funzione javascript che &#39;tenta&#39; di convertire una valore in un un intero (vedi la seconda parte del tutorial).&lt;br /&gt;
&lt;br /&gt;
Per verificare se un valore non è &amp;nbsp;numero&amp;nbsp;si utilizza la funzione &lt;i&gt;isNaN&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var checkNumber = &lt;b&gt;isNaN&lt;/b&gt;(n1); &amp;nbsp;// &lt;i&gt;checkNumber = false, è un numero&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;checkNumber = &lt;b&gt;isNaN&lt;/b&gt;(n2); &amp;nbsp; // &lt;i&gt;checkNumber = true, non è un numero&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
La funzione &lt;i&gt;isNaN&lt;/i&gt; restituisce &lt;i&gt;true&lt;/i&gt; anche se la variabile non è un numero:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var checkNumber = &lt;b&gt;isNaN&lt;/b&gt;(&quot;testo qualsiasi&quot;); &amp;nbsp;// &lt;i&gt;=true&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Ma se la stringa contiene un numero:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var checkNumber = &lt;b&gt;isNaN&lt;/b&gt;(&quot;10&quot;); // &lt;i&gt;=false&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Quindi &amp;nbsp;la funzione &lt;i&gt;isNaN() &lt;/i&gt;verifica che il valore, anche se non di tipo numero, sia &quot;usabile&quot; come numero nelle operazioni aritmetiche.&lt;br /&gt;
La funzione &lt;i&gt;isNaN &lt;/i&gt;è equivalente alla seguente operazione:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var checkNumber =&amp;nbsp; (v*1)===&lt;/span&gt;&lt;b style=&quot;color: #cc0000;&quot;&gt;NaN&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
la moltiplicazione ci assicura un valore numerico., se, per esempio,&amp;nbsp;&lt;i&gt;v&amp;nbsp;&lt;/i&gt;contenesse la stringa &quot;10&quot;, il valore verrebbe correttamente convertito nel numero 10, altrimenti verrebbe restituito &lt;i&gt;NaN&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Infine il valore &quot;&lt;i&gt;null&quot;&lt;/i&gt; è un possibile valore per variabili di tipo oggetto:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = null;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(a) ); &amp;nbsp;// &lt;i&gt;show &quot;object&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( a ); &amp;nbsp;// &lt;i&gt;show &quot;null&quot;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Questo valore può essere restituito da una funzione che dovrebbe restituire un oggetto. Per es:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;myElement&quot;);&lt;/span&gt;&lt;br /&gt;
se non esiste nella pagina un elemento con id=&quot;myElement&quot;, il valore di &#39;el&#39; sarà &#39;null&#39; (vedi il tutorial sul DOM per interagire con la pagina HTML tramite javascript)&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Espressioni condizionali&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Le espressioni condizionali come in tutti i linguaggi più diffusi si verificano con l&#39;operatore &lt;i&gt;if&lt;/i&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(&lt;i&gt;condition&lt;/i&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;If(&lt;i&gt;condition&lt;/i&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(&lt;i&gt;condition&lt;/i&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else if(&lt;i&gt;condition2&lt;/i&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
In javascript un espressione condizionale non restituisce solo true o false, ma anche un valore che può essere null, undefined o NaN (Not a Number).&lt;br /&gt;
La condizione è quindi verificata se non restituisce i seguenti valori:&lt;br /&gt;
- false&lt;br /&gt;
- undefined&lt;br /&gt;
- null&lt;br /&gt;
- NaN&lt;br /&gt;
Ecco un esempio:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var a = &quot;ciao&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if( a==&quot;ciao&quot; ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;è un saluto&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
L&#39;espressione &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a==&quot;ciao&quot; &lt;/span&gt;restituisce &lt;i&gt;true &lt;/i&gt;(cioè è vera), per cui viene eseguita l&#39;istruzione alert che visualizza il messaggio &quot;è un saluto&quot;.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;Operatori di confronto e operatori logici&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Gli operatori di confronto restituiscono sempre un valore booleano true (vero) o false (falso), mentre, come vedremo in seguito, gli operatori logici in javascript hanno un comportamento differente nel senso che se applicati a valori booleani, restituiscono valori booleani, altrimenti possono restituire valori di altro tipo come stringhe, numeri, undefined, null, eccetera.&lt;br /&gt;
Segue la lista di questi operatori:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
!=&amp;nbsp;&lt;i&gt;not equals&lt;/i&gt;: (confronto)&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
|| &lt;i&gt;or (logico)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;amp;&amp;amp; &lt;i&gt;and (logico)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
! &lt;i&gt;not (logico)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
== &lt;i&gt;equals (confronto)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;gt; &lt;i&gt;greater&lt;/i&gt;&amp;nbsp;(confronto)&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;gt;= &lt;i&gt;greater or equals (confronto)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;lt; &lt;i&gt;less (confronto)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;lt;= &lt;i&gt;less or equals (confronto)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;
Esempio:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( a&amp;lt;10 || a&amp;gt;20 ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else if( b&amp;gt;10 &amp;amp;&amp;amp; b&amp;lt;=20 ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;//istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
E&#39; possibile assegnare il risultato di un&#39;espressione di questo tipo ad una variabile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var result = a&amp;lt;10;&lt;/span&gt;&lt;br /&gt;
Il valore della variabile result sarà quindi &lt;i&gt;true &lt;/i&gt;o &lt;i&gt;false&lt;/i&gt;.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;u&gt;Assegnazioni condizionali (operatore condizionale ternario)&lt;/u&gt;&lt;br /&gt;
E&#39; possibile scrivere una condizione direttamente su un&#39;assegnazione:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a = b ==1 ? &quot;text1&quot; : &quot;text2&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
quindi se &quot;&lt;i&gt;b&quot;&lt;/i&gt; è uguale a 1, viene assegnato ad &quot;&lt;i&gt;a&quot;&lt;/i&gt; la stringa &quot;text1&quot; altrimenti &quot;text2&quot;.&lt;/div&gt;
&lt;div&gt;
nota: l&#39;espressione precedente è equivalente a: &amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;a = b ==1 &amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&quot;text1&quot;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;|| &quot;text2&quot;;&lt;/span&gt;&lt;br /&gt;
La condizione è il termine prima del punto di domanda&lt;i&gt;&amp;nbsp;&lt;/i&gt;e i due valori in caso rispettivamente di true e false sono separati dal caratteri due punti&amp;nbsp;.&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;expr&amp;nbsp;&lt;b&gt;?&lt;/b&gt; value1 &lt;b&gt;:&lt;/b&gt; value2&lt;/i&gt;&lt;/div&gt;
Possiamo inserire questo tipo di condizioni all&#39;interno di una operazione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a = b + (c==2 &amp;nbsp;|| c==4 ? 4 : 8);&lt;/span&gt;&lt;br /&gt;
quindi alla variabile &quot;&lt;i&gt;b&quot;&lt;/i&gt; verrà sommato il valore 4 se &quot;&lt;i&gt;c&quot;&lt;/i&gt; è uguale a 2 o 4, altrimenti verrà sommato il valore 8.&lt;br /&gt;
Possiamo utilizzare l&#39;espressione condizionale concatenando stringhe:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;sesso: &quot;+(gender==&quot;m&quot;?&quot;maschio&quot;:&quot;femmina&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Verificare undefined, NaN, null, false&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
In javascript &amp;nbsp;una condizione non è verificata se il valore di una variabile è &lt;i&gt;null, undefined, NaN o false&lt;/i&gt;. Per esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(b) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;good value&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;b is null, false, undefined or false&quot;);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Se &lt;i&gt;b=infinity&lt;/i&gt;, l&#39;espressione è verificata.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Nota&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
ho sperimentato che nel caso &quot;b&quot; = &lt;i&gt;undefined&lt;/i&gt; come nell&#39;esempio seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = undefined;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(b!=null){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;b is not null&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;b is null&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
la condizione non viene comunque verificata, come se &lt;i&gt;null&lt;/i&gt; fosse equivalente al valore &lt;i&gt;undefined.&lt;/i&gt;&lt;br /&gt;
Per verificare correttamente il valore &lt;i&gt;null&lt;/i&gt; dovremmo anche controllare il tipo della variabile:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(b!==null){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;alert(&quot;b is not null&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;b is null&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
Il simboli &quot;===&quot; e &quot;!==&quot; verificano anche il type della variabile. Nel nostro caso viene verificato anche che b sia di tipo &quot;object&quot;.&lt;br /&gt;
Senza un confronto del tipo, &lt;i&gt;undefined &lt;/i&gt;è equivalente a &lt;i&gt;null &lt;/i&gt;come a &lt;i&gt;NaN&lt;/i&gt;.&lt;br /&gt;
Ecco un altro esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = &quot;10&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( a==10 ) alert(&quot;equals 10&quot;);&lt;/span&gt;&lt;br /&gt;
La condizione è verificata perchè javascript converte la variabile &quot;a&quot; nel tipo &quot;number&quot;.&lt;br /&gt;
Per verificare anche che il tipo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = &quot;10&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( a===10 ) alert(&quot;equals 10&quot;);&lt;/span&gt;&lt;br /&gt;
la condizione non è quindi verificata.&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
Con l&#39;operatore &lt;i&gt;OR&lt;/i&gt;, oltre ai valori &quot;speciali&quot;, possiamo assicurarci se una variabile ha una valore &quot;valido:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = a || 0;&lt;/span&gt;&lt;br /&gt;
Normalmente si utilizza questo tipo di verifica in due casi:&lt;br /&gt;
1. variabile dichiarata in un altro file script; è sempre buona abitudine in questi casi effettuare una verifica perchè per qualche motivo il caricamento dello script è saltato; possiamo verificare l&#39;esistenza di una variaibile con questo controllo:&lt;br /&gt;
try {a;}catch(ex){ &amp;nbsp;alert(&quot;a not exists&quot;) &amp;nbsp;}&lt;br /&gt;
2. variabile è un argomento in una funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function(a) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;a = a ||0;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;....&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;u&gt;&lt;i&gt;Attenzione&lt;/i&gt;&lt;/u&gt;: se non dichiariamo la variabile &quot;a&quot; e la utilizziamo come nella seguente espressione, viene sollevato un errore:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = (a||0) +1; &amp;nbsp;// &lt;i&gt;javascript error!&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ora vediamo il caso con l&#39;operatore &lt;i&gt;AND&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = a &amp;amp;&amp;amp; b;&lt;/span&gt;&lt;br /&gt;
se solo una della due variabili non è mai stata dichiarata, &lt;u&gt;&amp;nbsp;si genera un errore javacript&lt;/u&gt;.&lt;br /&gt;
Se una delle due variabili &quot;a&quot; o &quot;b&quot; è &lt;i&gt;null &lt;/i&gt;(o &lt;i&gt;undefined&lt;/i&gt;, &lt;i&gt;false&lt;/i&gt;, &lt;i&gt;NaN&lt;/i&gt;), c sarà &lt;i&gt;null&lt;/i&gt;&amp;nbsp;(o &lt;i&gt;undefined&lt;/i&gt;, false, NaN).&lt;br /&gt;
Esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = null &amp;amp;&amp;amp; false; &amp;nbsp;// &lt;i&gt;c=null&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Se invece valori verificati sono&quot;validi&quot;, allora &quot;&lt;i&gt;c&lt;/i&gt;&quot; avrà il valore dell&#39;ultima variabile, &amp;nbsp;come nel seguente esempio;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var c = 5 &amp;amp;&amp;amp; 16; &amp;nbsp;// &lt;i&gt;c = 16&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
Concludiamo con l&#39;operatore NOT.&lt;br /&gt;
Questo operatore restituisce &lt;i&gt;true&lt;/i&gt; se il valore è &lt;i&gt;null, undefined, NaN &lt;/i&gt;o&lt;i&gt; false&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = null;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = !a; &amp;nbsp; // &lt;i&gt;b = true&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a; // oppure a = undefined&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = !a; &amp;nbsp; // &lt;i&gt;b = true&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a = NaN;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = !a; &amp;nbsp; // &lt;i&gt;b = true&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a = true;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = !a; &amp;nbsp; //&lt;i&gt; b = true&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Negando due volte &quot;&lt;i&gt;a&quot;&lt;/i&gt;&amp;nbsp;viene restituito true se il valore è &quot;valido&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = !!a;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
equivalente a:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = a ? true : false;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Switch&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Al posto di una serie di &lt;i&gt;if/else&lt;/i&gt;, può essere più comodo (e forse più chiaro) usare &lt;i&gt;switch&lt;/i&gt; per &amp;nbsp;eseguire una serie di istruzioni in base al valore di una certa variabile:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;switch&lt;/b&gt;(&lt;i&gt;param&lt;/i&gt;){&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &lt;b&gt;case&lt;/b&gt; a:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &lt;b&gt;case&lt;/b&gt; b: case c;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;default&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
Come è noto, senza il &lt;i&gt;break, &lt;/i&gt;verrebbero eseguire le istruzioni del blocco &quot;case&quot; successivo.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Loop (cicli)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ciclo &lt;i&gt;for&lt;/i&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;for&lt;/b&gt;(var i=0; i&amp;lt;10; i++) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
all&#39;interno delle parentesi del &lt;i&gt;for, &lt;/i&gt;vengono specificati tre argomenti separati da &quot;;&quot;, il primo inizializza la variabile contatore, il secondo specifica la condizione che deve essere verificata per eseguire il blocco di istruzioni, il terzo modifica il valore del contatore ad ogni ciclo (es. i++, i--, i+5, i*2, etc).&lt;br /&gt;
Si utilizza &quot;&lt;i&gt;break&quot;&lt;/i&gt; per interrompere l&#39;esecuzione del ciclo &lt;i&gt;for&lt;/i&gt; e &quot;&lt;i&gt;continue&quot;&lt;/i&gt; per passare al ciclo successivo senza quindi eseguire le istruzioni successive nel blocco.&lt;br /&gt;
Ecco un esempio che cerca i primi 10 numeri pari in un array:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var arr = [5,8,10,20,23,37,93,102,243,332,372, 423, 444, 523, 593, 700];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var evenNumbers = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var sep = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;for&lt;/b&gt;(var i=0; &amp;nbsp;i&amp;lt;arr.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;if( i==10 )&amp;nbsp;&lt;b&gt;break&lt;/b&gt;; //esce dal loop se abbiamo ciclato gia 10 numeri&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var v = arr[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;if( v%2!=0 ) &lt;b&gt;continue&lt;/b&gt;; // se è un numero dispari, passo al ciclo successivo&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;eventNumbers += sep + v;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;sep = &quot;,&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(eventNumbers);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ciclo &lt;i&gt;for&lt;/i&gt; per oggetti:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;for&lt;/b&gt;(var property in obj) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var value = obj[property];&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;...&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ciclo &lt;i&gt;while&lt;/i&gt; (a condizione iniziale):&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;while&lt;/b&gt;(&lt;i&gt;condition&lt;/i&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ciclo &lt;i&gt;do/while&lt;/i&gt; (a condizione finale, il blocco di istruzione viene eseguito almeno una volta):&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;do&lt;/b&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;b&gt;while&lt;/b&gt;(condition);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Funzioni&lt;/span&gt;&lt;br /&gt;
Le funzioni si definiscono nella seguente maniera:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;doSomething&lt;/b&gt;(param1, param2){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt;istruzioni&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
La funzione si chiama &lt;i&gt;doSomething&lt;/i&gt; e accetta due parametri in ingresso. Tra parentesi graffe si inserisce quindi il codice da eseguire quando la funzione viene invocata.&lt;br /&gt;
Per invocare la funzione precedentemente definita basta scrivere:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;doSomething(&quot;helloworld&quot;,5);&lt;/span&gt;&lt;br /&gt;
I parametri di una funzione non sono obbligatori, infatti la funzione può essere invocata senza passare argomenti:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;doSomething();&lt;/span&gt;&lt;br /&gt;
spetta alle istruzioni della funzione verificare se un certo parametro è stato passato o meno.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function doSomething(param1, param2) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; if( !param1 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; param1 = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
oppure, come abbiamo visto in precedenza:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function doSomething(param1, param2) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;param1 = param1 || 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; ...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
E buona abitudine assegnare dei valori dei default ai parametri in ingresso ad una funzione.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Per maggiori dettagli sulle funzioni vedere il tutorial:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Ora proviamo un esempio completo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var clickCount = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function showClickCount(){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; clickCount++;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(clickCount);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;button onclick=&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;showClickCount();&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot;&amp;gt;click me&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
La funzione &lt;i&gt;showClickCount&lt;/i&gt; incrementa di 1 la variabile &lt;i&gt;clickCount&lt;/i&gt; (inizializzata a 0) e la mostra in una finestra tramite l&#39;istruzione &lt;i&gt;alert&lt;/i&gt;.&lt;br /&gt;
Ogni volta che viene premuto il pulsante &quot;click me&quot;, viene quindi invocata la funzione.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Strumenti&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Ormai ogni moderno browser è dotato di uno strumento per effettuare debugging su codice javascript.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;i&gt;- Firefox:&amp;nbsp;&lt;/i&gt;&amp;nbsp;installare il plugin Firebug&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;i&gt;- Internet Explorer&lt;/i&gt;&amp;nbsp;(IE8/IE9): cercare nel menu strumenti per developer, da questo strumento è possibile verificare la compatibilità fino alla versione IE7&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;i&gt;- Chrome:&lt;/i&gt;&amp;nbsp;cercare nel menu strumenti per sviluppatori&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;i&gt;- Opera:&lt;/i&gt;&amp;nbsp;se non ricordo male il tool si chiama &quot;drangonfly&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;i&gt;Safari:&lt;/i&gt;&amp;nbsp;cito le indicazioni dal sito ufficiale &amp;nbsp;&quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #797c80; font-family: &#39;Lucida Grande&#39;, Geneva, Arial, Verdana, sans-serif; line-height: 21px;&quot;&gt;enable the Develop menu in Safari&#39;s Advanced preferences.&lt;/span&gt;&quot;, il tool sembra lo stesso di Chrome.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Questi strumenti oltre ad una console javascript, consentono di analizzare il contenuto html e gli stili applicati. Consentono anche di editare i contenuti.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Alcuni permettono anche di accedere alle nuove funzionalità HTML5 come il local db sqlite su cui si possono effettuare query sql (chrome e safari).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;E interessante la funzionalità &quot;profiler&quot; che consente di misurare i tempi di esecuzione del nostro codice javascript.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Imparare ad utilizzare questi strumenti è importante per creare codice javascript solido e performante. Inoltre &amp;nbsp;ci consente di individuare gli errori più velocemente.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Ogni nuovo browser supporta l&#39;oggetto &quot;console&quot; che consente di loggare nel nostro codice javascript:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-size: xx-small;&quot;&gt;console.log(&quot;a=&quot;+a);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;il messaggio viene stampato sulla console javascript.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/455004036421596068/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html#comment-form' title='1 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/455004036421596068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/455004036421596068'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html' title='Javascript le basi (1a parte)'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-5664483843916438074</id><published>2011-06-25T12:27:00.015+02:00</published><updated>2019-12-20T14:27:45.508+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>Javascript &amp; gwt tutorials</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;HTML&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;Utilizzo corretto di alcuni attributi&amp;nbsp;&lt;/i&gt;(utile per i programmatori e per grafici css)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/09/html-utilizzo-corretto-degli-attributi.html&quot;&gt;http://gheryd.blogspot.com/2011/09/html-utilizzo-corretto-degli-attributi.html&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;Javascript (ES6)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
Aggiornamento javascript ES6&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2019/07/javascript-es6-es2015.html&quot;&gt;http://gheryd.blogspot.com/2019/07/javascript-es6-es2015.html&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;Javascript (ES5)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Tutorial di base &lt;/i&gt;(1a parte, sintassi e basi del linguaggio)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-tutorial-di-base.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Tutorial di base&amp;nbsp;&lt;/i&gt;(2a parte, operazioni matematiche, su string, array etc)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-le-basi-2a-parte.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Manipolare il DOM&lt;/i&gt; (Document object model)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-manipolare-dom-codice.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-manipolare-dom-codice.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Programmazione ad oggetti&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Programmazione eventi browser compatibili&lt;/i&gt;&amp;nbsp;(esempi completi:&amp;nbsp;&lt;i&gt;currency text box&lt;/i&gt;,&amp;nbsp;&lt;i&gt;editable table&lt;/i&gt;)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html&quot;&gt;http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Funzione parseint&lt;/i&gt; (caso specifico per i valori &quot;08&quot; e 09)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/javascript-parseint-per-valori-08-e-09.html&quot;&gt;http://gheryd.blogspot.com/2011/05/javascript-parseint-per-valori-08-e-09.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Regular expression targa italiana&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/javascript-regular-expression-targa.html&quot;&gt;http://gheryd.blogspot.com/2011/05/javascript-regular-expression-targa.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Controllare se jquery è caricato (o qualsiasi altro script)&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/07/javascript-check-jquery-loaded.html&quot;&gt;http://gheryd.blogspot.com/2011/07/javascript-check-jquery-loaded.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Ricerca dei numeri primi (crivello di Eratostene)&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/08/javascript-numeri-primi.html&quot;&gt;http://gheryd.blogspot.com/2011/08/javascript-numeri-primi.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Grepolis tools&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/da-ex-giocatore-di-grepolis-mi-ero.html&quot;&gt;http://gheryd.blogspot.com/2011/05/da-ex-giocatore-di-grepolis-mi-ero.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;GWT&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Widget Currency Text Box&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/04/gwt-currency-generic-number-text-box.html&quot;&gt;http://gheryd.blogspot.com/2011/04/gwt-currency-generic-number-text-box.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Detect popup blocker&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/03/gwt-detect-popup-blocker-rilevazione.html&quot;&gt;http://gheryd.blogspot.com/2011/03/gwt-detect-popup-blocker-rilevazione.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Widget Tree&lt;/i&gt; (impedire da tastiera la selezione degli item nascosti)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/03/se-si-nasconde-un-item-di-un-tree.html&quot;&gt;http://gheryd.blogspot.com/2011/03/se-si-nasconde-un-item-di-un-tree.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Developer plugin&lt;/i&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2010/08/plugins-gwt-developer-plugin-per-chrome.html&quot;&gt;http://gheryd.blogspot.com/2010/08/plugins-gwt-developer-plugin-per-chrome.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Suggest box&lt;/i&gt; (forzare la visualizzazione della lista sul campo vuoto)&lt;span id=&quot;goog_106381493&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_106381494&quot;&gt;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2010/02/gwt-forzare-la-visualizzazione-per-il.html&quot;&gt;http://gheryd.blogspot.com/2010/02/gwt-forzare-la-visualizzazione-per-il.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;gwt &amp;amp; gears &lt;/i&gt;(fixing del plugin)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2010/02/utilizzando-gwt-2.html&quot;&gt;http://gheryd.blogspot.com/2010/02/utilizzando-gwt-2.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt; gwt &amp;amp; php&lt;/i&gt; (utilizzare i servizi creati con php su gwt e lavorare in debug su ecplise)&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/09/gwt-tutorial-utilizzare-gwt-con-php.html&quot;&gt;http://gheryd.blogspot.com/2011/09/gwt-tutorial-utilizzare-gwt-con-php.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Gestire Eventi riga per FlexTable&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2012/01/gwt-eventi-righe-per-flextable.html&quot;&gt;http://gheryd.blogspot.com/2012/01/gwt-eventi-righe-per-flextable.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Mostrare/nascondere pannelli con un doppio click sugli splitters dellp SplitLayoutPanel&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2012/02/public-class-splitlayoutpanelext.html&quot;&gt;http://gheryd.blogspot.com/2012/02/public-class-splitlayoutpanelext.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Questi tutorials sono nati dai miei appunti che ho raccolto nel tempo durante la mia esperienza lavorativa come programmatore web.&lt;br /&gt;
Nel tempo li ho riordinati e li ho inseriti in questo blog in modo che fossero sempre disponibili.&lt;br /&gt;
Li ho poi resi pubblici sperando che possano essere di utilità non solo per nuovi programmatori ma anche per i più esperti. ;)&lt;br /&gt;
Consigli, proposte, segnalazioni di errore sono ben accetti :)&lt;br /&gt;
Quindi aggiungete pure commenti.&lt;br /&gt;
Beh, buona lettura, anzi, buona programmazione!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/5664483843916438074/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html#comment-form' title='1 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/5664483843916438074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/5664483843916438074'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html' title='Javascript &amp; gwt tutorials'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-9145434986394891681</id><published>2011-06-18T17:17:00.046+02:00</published><updated>2011-08-03T19:54:47.949+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dell vostro 3750"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu  11.04"/><title type='text'>Ubuntu 11.04 DELL VOSTRO 3750 CRASH</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/06/ubuntu-1104-dell-vostro-3750-crash.html&amp;amp;sl=it&amp;amp;tl=en&amp;amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In maggio 2011 La mia esperienza con Ubuntu 11.04 sulla mia nuova macchina DELL Vostro 3750 è stato un completo disastro.&lt;br /&gt;
Dopo una settimana il sistema è andato in crash e non era possibile reinstallare &amp;nbsp;neanche da cd.&lt;br /&gt;
La macchina è stata acquistata a maggio 2011. Le caratteristiche tecniche sono in questa pagina: &lt;a href=&quot;http://www.dell.com/nz/business/p/vostro-3750/pd?oc=u5203d4nz&amp;amp;model_id=vostro-3750&quot;&gt;specifiche tecniche Dell Vostro 3750&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Inizialmente per risolvere i problema ho reinstallato Windows Seven, e poi in una seconda partizione ho installato Ubuntu 10.04 LTS con un kernel 2.6.38.&amp;nbsp;Ma non funzionavano gli effetti visivi.&lt;br /&gt;
Poi ultimamente (fine luglio 2011) mi sono deciso a riprovare la versione 11.04. Ho cercato in mezzo web, ho installato diversi pacchetti .deb per far funzionare la scheda NVIdia, ho cambiato impostazioni di avvio. Man mano che procedevo non vedevo alcun miglioramento, anzi, gli errori crescevano finchè il sistema è andato in crash definitivo, senza la possibilità di avvio da cdrom. Non riuscivo a far partire neanche il cd della versione 10.04 con le impostazioni &quot;nomodeset&quot; o &quot;acpi=off&quot;.&lt;br /&gt;
Poi quando stavo per mollare, ho voluto fare un ultimo tentativo con un installatore testuale. Ho provato &amp;nbsp;la versione 11.04 alternate e sembrava funzionare senza la necessità di &quot;smanettare&quot;.&lt;br /&gt;
Poi dopo due giorni, mentre stavo scaricando dei file con filezilla è andato in completo crash.&lt;br /&gt;
Per cui devo ritornare alla versione 10.04 LTS.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Ubuntu 10.04 LTS con kernel 2.6.38&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Se sul vostro Dell Vostro 3750 non riuscite proprio ad utilizzare Ubuntu versine 11.04, provate la versione Ubuntu 10.04 LTD (&lt;i&gt;Long Term Support&lt;/i&gt;) e poi aggiornate il kernel per il riconoscimento dei componenti harware (altrimenti non potete utilizzare la wireless e la grafica è a 1024)&lt;br /&gt;
&lt;div style=&quot;background-color: #00aa00; border: 2px solid green; color: white; padding: 10px;&quot;&gt;&lt;b&gt;- ho reinstallato Windows Seven da cd fornito da Dell con tutti i drivers.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;- da Seven ho ridotto lo spazio della partizione primaria tramite pannello di controllo-&amp;gt;strumenti di amministrazione-&amp;gt;gestione disco; da 500 gb sono riuscito a liberare solo 250 gb.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;- ho scaricato il file .iso UBUNTU 10.04 LTS 64 bit (dalla pagina ufficiale di ubuntu in alternativa alla 11.04) e l&#39;ho masterizzato su cd (tasto destro sul file, masterizza immagine su cd).&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;- ho fatto il boot dal cd&amp;nbsp; (riavviando il computer tenere premuto F12); durante l&#39;installazione di Ubuntu 10.04 ho creato due partizioni nello spazio libero, uno per root &quot;/&quot; (50gb) e una per &quot;/home&quot; (150gb) per preservare dati e configurazioni in caso di reinstallazione&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;- con il kernel fornito su cd non mi veniva riconosciuta la scheda grafica e la wireless, così ho installato il nuovo kernel 2.6.38-1-generic. (vedi comandi sotto)&lt;/b&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: black; color: white; overflow: auto; padding: 5px;&quot;&gt;gheryd@gheryd-laptop:~$ sudo add-apt-repository ppa:kernel-ppa/ppa
gheryd@gheryd-laptop:~$ sudo apt-get update
gheryd@gheryd-laptop:~$ sudo apt-get install linux-headers-2.6.38-1-generic linux-image-2.6.38-1-generic
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/9145434986394891681/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/06/ubuntu-1104-dell-vostro-3750-crash.html#comment-form' title='8 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/9145434986394891681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/9145434986394891681'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/06/ubuntu-1104-dell-vostro-3750-crash.html' title='Ubuntu 11.04 DELL VOSTRO 3750 CRASH'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-1908635049388814566</id><published>2011-06-08T23:15:00.074+02:00</published><updated>2011-12-20T09:55:30.140+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>javascript manipolare DOM,  codice browser compatibile</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Indice dei tutorials:&amp;nbsp;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Indice&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Manipolazione di base&lt;/li&gt;
&lt;li&gt;Ottimizzare le performances&lt;/li&gt;
&lt;li&gt;Operazione con gli attributi&lt;/li&gt;
&lt;li&gt;Aggiungere html&lt;/li&gt;
&lt;li&gt;Gestire eventi&lt;/li&gt;
&lt;li&gt;Gestire le classi e le proprietà di stile&lt;/li&gt;
&lt;li&gt;Mostrare/nascondere un elemento&lt;/li&gt;
&lt;li&gt;Select&lt;/li&gt;
&lt;li&gt;CheckBox&lt;/li&gt;
&lt;li&gt;Caricare uno script&lt;/li&gt;
&lt;li&gt;Caricare un css&lt;/li&gt;
&lt;li&gt;Templates&lt;/li&gt;
&lt;/ul&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;i&gt;Introduzione&lt;/i&gt;&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
In javascript, ogni elemento grafico inserito nella pagina HTML è rappresentato da un oggetto accessibile tramite l&#39;oggetto &quot;document&quot;.&lt;br /&gt;
L&#39;oggetto &quot;document&quot; è una proprietà dell&#39;oggetto &quot;window&quot; e viene popolato con una struttura ad albero durante il caricamento della pagina.&lt;br /&gt;
La struttura che viene così creata è il DOM, document object model, cioè una rappresentazione a oggetti di tutti i componenti della pagina HTML.&lt;br /&gt;
Se conoscete XML, vi saranno familiari i comandi in questo tutorial per manipolare questi oggetti che di base sono chiamati nodi (node). Ogni nodo può contenere dei nodi figli (child nodes).&lt;br /&gt;
L&#39;oggetto &quot;element&quot; è un particolare tipo di nodo che rappresenta un tag html.&lt;br /&gt;
Esistono altri tipi di nodi, come per esempio gli attributi dell&#39;elemento, oppure i commenti.&lt;br /&gt;
Anche il testo inserito all&#39;interno di una tag sarà rappresentato nel DOM come nodo figlio.&lt;br /&gt;
Esistono delle &quot;scorciatoie&quot; che consentono di cercare elementi esistenti nella pagina, il più usato è sicuramente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;myId&quot;);&lt;/span&gt;&lt;br /&gt;
Il metodo restituisce un oggetto &lt;i&gt;element&lt;/i&gt; che ha come attributo &lt;i&gt;id = &quot;myId&quot;&lt;/i&gt;.&lt;br /&gt;
Con javascript &amp;nbsp;possiamo modificare gli elementi esistenti cambiandone l&#39;aspetto grafico per esempio, oppure crearne di nuovi e farli apparire dove ci è necessario come per esempio aggiungere una riga ad una tabella o un elemento in una lista.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Manipolazione di base&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Creare un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.createElement(&quot;div&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Creare un elemento di testo:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var txt = document.createTextNode(&quot;Hello world!&quot;);&lt;/span&gt;&lt;/div&gt;
Ottenere un elemento dal suo id:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;myId&quot;);&lt;/span&gt;&lt;br /&gt;
se l&#39;elemento non è nella pagina &lt;i&gt;el&lt;/i&gt; sarà nullo, verificare prima di accedere alle proprietà dell&#39;elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if( el ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot; element exists&quot; );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #f0f0f0; border: 1px solid gray; padding: 5px;&quot;&gt;
Nota: per accedere ad elementi gia esistenti, dovrete attendere la fine del caricamento della pagina come nell&#39;esempio seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function init() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var el = document.getElementById(&quot;myDiv&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; ....&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow; color: #999999;&quot;&gt; onload=&quot;init()&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;div id=&quot;myDiv&quot;&amp;gt;....&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/div&gt;
Ottenere elementi in base al tag:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var els = document.getElementsByTagName(&quot;input&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;els.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var el = els[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Ottenere il nome del tag&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var tagname = el.tagName;&lt;/span&gt;&lt;br /&gt;
Aggiungere un elemento alla fine:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;elParent.appendChild(elChild);&lt;/span&gt;&lt;br /&gt;
Inserire un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;elParent.insertBefore(newEl, elChild);&lt;/span&gt;&lt;br /&gt;
Rimuovere un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;elParent.removeChild(elChild);&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Sostituire un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;elParent.replaceChild(newChild, oldChild);&lt;/span&gt;&lt;br /&gt;
Inserire un elemento all&#39;inizio:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;elParent.insertBefore(elChild, elParent.childNodes[0]);&lt;/span&gt;&lt;/div&gt;
Ottenere la lista (array) degli elementi figli:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var nodes= elParent.childNodes;&lt;/span&gt;&lt;br /&gt;
Ottenere il primo figlio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var node = elParent.firstChild;&lt;/span&gt;&lt;br /&gt;
Ottenere l&#39;ultimo figlio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var node = elParent.lastChild;&lt;/span&gt;&lt;br /&gt;
Ottenere il fratello successivo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var node = el.nextSibling;&lt;/span&gt;&lt;br /&gt;
Ottenere il fratello precendente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var node = el.previousSibling;&lt;/span&gt;&lt;br /&gt;
Sapere il tipo di nodo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var type = node.nodeType;&lt;/span&gt;&lt;br /&gt;
il valore restituito è un numero, di solito interessa verificare se il tipo è relativo ad un element node o un text node come nell&#39;esempio seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;if(&amp;nbsp;&lt;/span&gt;type&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot;&gt;&amp;nbsp;== 1) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;is element&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;// node.nodeName = &quot;DIV&quot; //=tagName&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var el = node;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;}else if(&lt;/span&gt;type&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot;&gt;==3) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;is text&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;// node.nodeName = &quot;#text&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var text = node.nodeValue;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Cercare il primo elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var firstEl = null;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var children = parentEl.childNodes;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;children.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var node = children[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;if(node.nodeType==1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;firstEl = node;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
in modo analogo per cercare l&#39;ultimo elemento:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var lastEl = null;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var children = parentEl.childNodes;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;children.length&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;; i&amp;gt;=0; i--) {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var node = children[i];&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;if(node.nodeType==1) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;lastEl&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;= node;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Ottenere l&#39;elemento padre:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;var parentEl = el.parentNode&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Ottimizzare le performances&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Se dobbiamo aggiungere molti elementi figli come dell&#39;esempio seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var container = document.getElementById(&quot;idContainer&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;100; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var child = document.createElement(&quot;p&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; child.appendChild( document.createTextNode(&quot;paragraph &quot;+i) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;container.appendChild(child);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
per migliorare le performances in alternativa è possibile creare un frammento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var &amp;nbsp;docFrag= document.createDocumentFragment();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;100; i++){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;var child = document.createElement(&quot;p&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; child.appendChild( document.createTextNode(&quot;paragraph &quot;+i) );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;docFrag&lt;span class=&quot;Apple-style-span&quot;&gt;.appendChild(child);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;container.appendChild(docFrag);&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
è equivalente all&#39;esempio precedente, ma molto più veloce perchè tutti gli elementi sono aggiunti alla pagina alla fine con un&#39;unica istruzione.&lt;br /&gt;
&lt;br /&gt;
In generale, è sempre meglio aggiungere elementi alla pagine verso la fine.&lt;br /&gt;
Per esempio, nel caso di creazione di una tabella:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var table = document.createElement(&quot;table&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #990000; color: #f4cccc;&quot;&gt;container.appendChild(table);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var tbody = document.createElement(&quot;tbody&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;table.appendChild(tbody);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var r=0;r&amp;lt;100; r++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var tr = document.createElement(&quot;tr&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;tbody.appendChild(tr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; for(var c=0;c&amp;lt;10;c++){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var td = document.createElement(&quot;td&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.appendChild(td);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;td.appendChild(document.createTextNode(&quot;cell &quot;+r+&quot;,&quot;+c));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
aggiungendo la tabella subito nella pagina prima di popolarla di righe e colonne, rallenta parecchio l&#39;esecuzione perchè costringe il browser a renderizzare all&#39;istante la cella ad ogni ciclo del loop di popolamento.&lt;br /&gt;
&lt;br /&gt;
Invece&amp;nbsp;spostando alla fine l&#39;istruzione evidenziata miglioriamo le prestazioni perchè la tabella è gia completa del suo contenuto, e la renderizzazione avviene in una sola volta.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var table = document.createElement(&quot;table&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var tbody = document.createElement(&quot;tbody&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;table.appendChild(tbody);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var r=0;r&amp;lt;100; r++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var tr = document.createElement(&quot;tr&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; tbody.appendChild(tr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; for(var c=0;c&amp;lt;10;c++){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var td = document.createElement(&quot;td&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.appendChild(td);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;td.appendChild(document.createTextNode(&quot;cell &quot;+r+&quot;,&quot;+c));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #990000; color: #f4cccc;&quot;&gt;container.appendChild(table);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Operazione con gli attributi&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Settare il valore di un attributo di un elemento:&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.setAttribute(&quot;id&quot;, &quot;myId&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
oppure&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.id = &quot;myId&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ottenere il valore di un attributo&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var id = el.getAttribute(&quot;id&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
oppure&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var id = el.id;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Rimuovere un attributo&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.removeAttribute(&quot;id&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
oppure&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.id = null;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ottenere la lista degli attributi:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var attrs = el.attributes,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;attrs.length; i++) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var attr = attrs[i];&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var name = attr.nodeName;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var value = attr.nodeValue;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;....&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
Può essere interessante aggiungere un attributo &quot;custom&quot; come nell&#39;esempio seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var textbox = document.getElementById(&quot;myInput&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;textbox.valueDefault = textbox.value;&lt;/span&gt;&lt;br /&gt;
in questa istruzione ho aggiunto la proprietà &quot;valueDefault&quot; che non esiste normalmente; questa istruzione potrebbe essere eseguita sull&#39;onload della pagina;&amp;nbsp;sull&#39;onclick di un bottone per &amp;nbsp;ripristinare il valore iniziale della textbox basta utilizzare la seguente istruzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;textbox.value = textbox.valueDefault;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Aggiungere html&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Settare html:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.innerHTML = &quot;&amp;lt;a href=&#39;#&#39;&amp;gt;my link&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;&lt;br /&gt;
tutti gli eventuali figli verranno rimossi.&lt;br /&gt;
Aggiungere html:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.innerHTML += &quot;&amp;lt;a href=&#39;#&#39;&amp;gt;my link&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;&lt;br /&gt;
Inserire html all&#39;inizio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.innerHTML = &quot;&amp;lt;a href=&#39;#&#39;&amp;gt;my link&amp;lt;/a&amp;gt;&quot;+el.innerHTML;&lt;/span&gt;&lt;br /&gt;
A mio giudizio è meglio evitare di utilizzare innerHTML se non per aggiungere un semplice testo formattato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.innerHTML = &quot;&amp;lt;b&amp;gt;title&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;i&amp;gt;italic&amp;lt;/i&amp;gt;&amp;lt;br/&amp;gt;etc....&quot;;&lt;/span&gt;&lt;br /&gt;
Per i casi &amp;nbsp;come quello dell&#39;esempio precedente del link preferisco operare nel modo seguente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var link = document.createElement(&quot;a&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;link.href = &quot;#&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;link.appendChild( document.createTextNode(&quot;my link&quot;) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.appendChild(link);&lt;/span&gt;&lt;br /&gt;
La proprietà innerHTML è utile per svuotare in maniera semplice un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el,innerHTML = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
Importante: non aggiungete nel innerHTML attributi di eventi perchè non funzionano su ie:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.innerHTML = &quot;&amp;lt;a href=&#39;#&#39; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow; color: #cc0000;&quot;&gt;onclick=&#39;alert(clicked);&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;&#39;&lt;/span&gt;&amp;gt;my link&amp;lt;/a&amp;gt;&quot;;&lt;/span&gt;&lt;br /&gt;
occorre crearsi l&#39;elemento come dell&#39;esempio precedente a aggiungere l&#39;handler così:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;link.onclick = function(event){ alert(&quot;clicked&quot;) }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Gestire eventi&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Registrare un handler di un evento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;div.onclick = function(event){ alert(&quot;clicked&quot;) }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
E&#39; possibile specificare delle istruzioni direttamente dentro il codice HTML:&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;input type=&quot;checkbox&quot; name=&quot;myCheck&quot; onClick=&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;alert(&#39;checked: &#39;+this.checked)&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
Il termine &lt;i&gt;this &lt;/i&gt;si riferisce all&#39;elemento.&lt;br /&gt;
&lt;br /&gt;
Per maggiori dettagli sulla gestione degli eventi vedere il seguente post:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html&quot; style=&quot;color: #174a82; text-decoration: none;&quot;&gt;http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Gestire le classi e le proprietà di stile&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Settare una classe di stile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.className = &quot;myClass&quot;;&lt;/span&gt;&lt;br /&gt;
Aggiungere una classe di stile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.className += &quot; &quot;+&quot;myClass2&quot;;&lt;/span&gt;&lt;br /&gt;
Sostituire una classe di stile con un&#39;altra:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.className =&amp;nbsp;el.className.replace(&quot;oldClass&quot;, &quot;newClass&quot;);&lt;/span&gt;&lt;br /&gt;
Rimuovere una classe di stile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.className =&amp;nbsp;el.className.replace(&quot;myClass&quot;, &quot;&quot;);&lt;/span&gt;&lt;br /&gt;
Verificare se ha una classe di stile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var hasMyClass =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.className.indexOf(&quot;myClass&quot;)&amp;gt;-1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;hasMyClass&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;has class&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Ottenere un&#39;array di classi di stile&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var classes = el.className.split(&quot; &quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;classes.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var class = classes[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Settare proprietà di stile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.borderColor = &quot;red&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.fontSize = &quot;10px&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.textAlign = &quot;right&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.backgroundColor = &quot;#faa&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.border = &quot;1px solid #000&quot;;&lt;/span&gt;&lt;br /&gt;
in generale la proprietà in &lt;i&gt;javascript&lt;/i&gt; è uguale alla proprietà &lt;i&gt;css&lt;/i&gt; senza trattini:&lt;br /&gt;
border-color -&amp;gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.borderColor&lt;/span&gt;&lt;br /&gt;
font-size -&amp;gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.fontSize&lt;/span&gt;&lt;br /&gt;
text-align -&amp;gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.textAlign&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;background-color -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.style.&lt;/span&gt;backgroundColor&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Cercare tutti gli elementi con una certa classe di stile&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;function getElementsByClass(classname, elContainer) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;   if(!classname) return null;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;  &amp;nbsp;elContainer = elContainer || document.body;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;   var els = [];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;  &amp;nbsp;var findElClass = function(el) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;  &amp;nbsp;  &amp;nbsp;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;var nodes = el.childNodes;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;        for(var i=0; i&amp;lt;nodes.length; i++) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;            var node = nodes[i];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;            if(node.nodeType!=1) continue;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;            if(node.className.indexOf(classname)&amp;gt;-1)  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;els.push(node);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;findElClass(node);&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;        }&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;   }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;findElClass(elContainer);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;   return els;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;Mostrare/nascondere un elemento&lt;/u&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Mostrare:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;myElement&quot;).style.display=&quot;&quot;;&lt;/span&gt;&lt;br /&gt;
Nascondere:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;myElement&quot;).style.display=&quot;none&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;u&gt;Select&lt;/u&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var sel = document.getElementById(&quot;mySelect&quot;);&lt;/span&gt;&lt;br /&gt;
Ripuliamo la select dalle option esistenti:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;sel.options.length = 0;&lt;/span&gt;&lt;br /&gt;
Popoliamo la select con un option&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var opt = new Option(&quot;&quot;, &quot;value&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;try {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; sel.add(opt, null);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}catch(ex){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; sel.add(opt);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;opt.innerHTML = &quot;text&quot;;&lt;/span&gt;&lt;br /&gt;
l&#39;ultima istuzione ci consente di usare html entities come per esempio &quot;&amp;amp;egrave;&quot; E&#39; importante che l&#39;assegnazione della &amp;nbsp;proprietà innerHTML sia successiva all&#39;instruzione di inserimento della option all&#39;interno della select.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;CheckBox&lt;/span&gt;&lt;/b&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Recuperarne il riferimento DOM:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var cb = document.getElementById(&quot;myCheckbox&quot;);&lt;/span&gt;&lt;br /&gt;
Se è in un form si può ottenere in base al suo attributo name:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var cb = document.getElementById(&quot;myForm&quot;).myCheckbox;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;form id=&quot;&lt;b&gt;myForm&lt;/b&gt;&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;input id=&quot;&lt;b&gt;myCheckbox&lt;/b&gt;&quot; name=&quot;&lt;b&gt;myCheckbox&lt;/b&gt;&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
Modificarne lo stato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;cb.checked = true;&lt;/span&gt;&lt;br /&gt;
Verificare lo stato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;if(cb.checked) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;is checked&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Intercettarne il cambio di stato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;cb.onclick = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;//TODO handle event&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Caricare uno script&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;var script= document.createElement(&#39;script&#39;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.src = &#39;/js/myscript.js&#39;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.type = &#39;text/javascript&#39;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.async = &#39;true&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;var s = document.getElementsByTagName(&#39;script&#39;)[0];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;s.parentNode.insertBefore(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;, s);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Caricare un css&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;var css= document.createElement(&#39;link&#39;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.href = &#39;/css/mycss.css&#39;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.rel= &#39;stylesheet&#39;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;.type = &#39;text/css&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;css.media = &#39;all&#39;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;document.getElementsByTagName(&quot;head&quot;)[0].appendChild(css);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;u style=&quot;color: #3d85c6; font-style: italic; font-weight: bold;&quot;&gt;Templates&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Possiamo utilizzare una porzione di HTML adibita a template per creare altri elementi.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&amp;lt;div style=&quot;display:none&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;    &amp;lt;div id=&quot;template1&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;           &amp;lt;div id=&quot;&lt;b&gt;#id#&lt;/b&gt;&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;                  &amp;lt;span&amp;gt;#&lt;b&gt;text#&lt;/b&gt;&amp;lt;span&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;            &amp;lt;div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;   &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;   &amp;lt;div id=&quot;template2&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;          &amp;lt;div style=&quot;border:1px solid #CCC;background-color:#AAA&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; white-space: pre-wrap;&quot;&gt;#block#&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;   &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #fff2cc; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&amp;lt;div id=&quot;container&quot;&amp;gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Il codice HTML che utilizzeremo come  template non sarà visibile in quanto è inserito in un div nascosto.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Con il seguente codice javascript di esempio aggiungiamo ad un div contenitore nuovi elementi basati sui nostri template:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var tpl1 = document.getElementById(&quot;template1&quot;).innerHTML;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;var tpl2 = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;document.getElementById(&quot;template2&quot;).innerHTML;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var container = document.getElementById(&quot;container&quot;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;10;i++) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;     var block = block.replace(&quot;#text#&quot;, &quot;item text &quot;+i).&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;replace(&quot;#id#&quot;, &quot;item&quot;+i);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;     var block2 = tpl2&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; white-space: pre-wrap;&quot;&gt;.replace(&quot;#block#&quot;, block);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;     container.innerHTML += block2;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;La tecnica quindi consiste nel prendere il contenuto html di un template. Si sostituiscono le eventuali &quot;chiavi&quot; che abbiamo definito all&#39;interno dei template con il testo che si vuole visualizzare e infine si aggiunge il codice  html che si è preparato all&#39;interno del div contenitore.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre-wrap;&quot;&gt;Il vantaggio di usare questo sistema è il fatto di non dover creare elementi grafici all&#39;interno di codice javascript. La porzione di html che utilizziamo come template può essere modificata successivamente senza dover metter mano al codice javascript.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/1908635049388814566/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-manipolare-dom-codice.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1908635049388814566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1908635049388814566'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-manipolare-dom-codice.html' title='javascript manipolare DOM,  codice browser compatibile'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-6268920367752769091</id><published>2011-06-07T10:19:00.007+02:00</published><updated>2011-08-11T12:36:49.834+02:00</updated><title type='text'>ubuntu installare headers kernel for virtual box</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;/div&gt;Verifichiamo la versione del kernel&lt;br /&gt;
&lt;pre style=&quot;background: black; color: white; padding: 5px;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;uname -a&lt;/b&gt;
Linux gheryd-laptop &lt;span style=&quot;color: yellow;&quot;&gt;&lt;b&gt;2.6.38-10-generic-pae&lt;/b&gt;&lt;/span&gt; #44-Ubuntu SMP Thu Jun 2 21:50:56 UTC 2011 i686 i686 i386 GNU/Linux&lt;/pre&gt;Istalliamo gli headers:&lt;br /&gt;
&lt;pre style=&quot;background: black; color: white; padding: 5px;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;sudo apt-get install linux-headers-lbm-&lt;span style=&quot;color: yellow;&quot;&gt;2.6.38-10-generic-pae&lt;/span&gt;&lt;/b&gt;
&lt;/pre&gt;oppure&lt;br /&gt;
&lt;pre style=&quot;background: black; color: white; padding: 5px;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;sudo apt-get install linux-headers-lbm-&lt;span style=&quot;color: yellow;&quot;&gt;$(uname -r)&lt;/span&gt;&lt;/b&gt;
&lt;/pre&gt;&lt;br /&gt;
Riaggiorniamo virtual box con il nuovo kernel&lt;br /&gt;
&lt;pre style=&quot;background: black; color: white; padding: 5px;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;sudo /etc/init.d/vboxdrv setup&lt;/b&gt;
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/6268920367752769091/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/06/ubuntu-install-header-kernel-for.html#comment-form' title='1 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/6268920367752769091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/6268920367752769091'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/06/ubuntu-install-header-kernel-for.html' title='ubuntu installare headers kernel for virtual box'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-17319267053394857</id><published>2011-06-02T21:09:00.091+02:00</published><updated>2013-05-28T11:34:29.736+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>javascript programmazione ad oggetti</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Indice dei tutorials:&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;Indice&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Indroducendo&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Function&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Singleton&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Classe&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Visibilità e scope delle variabili&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Variabili static&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Prototype&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Ereditarietà&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Estendere una classe&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Cenni sull&#39;oggetto window&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Approfondimento&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;Introducendo&lt;/i&gt;&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Per chi è abituato alla classica programmazione ad oggetti in C o in Java, il primo impatto con javascript risulta poco familiare, e richiede un po&#39; di elasticità sia per quanto concerne la sintassi sia per la definizione di classe.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Javascript in quanto script e non linguaggio di programmazione puro tipizzato, permette molte libertà sugli oggetti,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Negli esempi utilizzerò analogie con la programmazione ad oggetti JAVA che spero possano aiutare nella comprensione dal punto di vista pratico.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Insomma quando parlo di classe in javascript, in realtà è un qualcosa che si comporta come una classe. Ma non lo è.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Prima di iniziare a parlare di classi e oggetti, verrà introdotto il concetto di funzione attraverso una serie di esempi. Ritengo che aver ben chiaro cosa siano le funzioni sia fondamentale nella programmazione avanzata in javascript e credo possa essere propedeutico per gli argomenti affrontati nelle sezioni successive.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&lt;i&gt;Function&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Come gia saprete è possibile definire una funzione in questa maniera:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function show(message) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
ma le funzioni in javascript sono oggetti il cui riferimento si può assegnare ad una variabile:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var show = function(message) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
la funzione può essere così invocata:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show(&quot;hello!&quot;);&lt;/span&gt;&lt;br /&gt;
oppure:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show.call(this, &quot;hello!&quot;);&lt;/span&gt;&lt;br /&gt;
o ancora&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;(show)(&quot;hello!&quot;);&lt;/span&gt;&lt;br /&gt;
in cui il termine &lt;i&gt;this&lt;/i&gt;&amp;nbsp;definisce lo &lt;i&gt;scope&lt;/i&gt; (spiegato in seguito) della funzione, invocata al di fuori di qualsiasi oggetto si riferisce all&#39;oggetto contenitore &lt;i&gt;window&lt;/i&gt;.&lt;br /&gt;
Una funzione, in quanto oggetto, può essere passata come parametro in ingresso ad un&#39;altra funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var myLogger = function(message) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function show(message, logger) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; logger(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show(&quot;hello&quot;, myLogger);&lt;/span&gt;&lt;br /&gt;
Possiamo &amp;nbsp;definirla in maniera anonima e invocarla al volo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(function(message){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;})(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
Possiamo definire una funzione all&#39;interno di un altra:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function show(message) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;function log() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;log();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
Ad una funzione possiamo far restituire un&#39;altro oggetto funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function createLogger() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return function(message){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;createLogger()(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var logger = createLogger();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;logger(&quot;hello2&quot;);&lt;/span&gt;&lt;br /&gt;
Il riferimento dell&#39;oggetto funzione può essere passato su più variabili:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var show = function(message) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(message);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var show2 = show;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show2(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
In quanto oggetti, le funzioni possono essere create tramite &lt;i&gt;new&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var show = new Function(&quot;message&quot;, &quot;alert(message);&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
perchè sono oggetti, la sintassi tipica di javascript ci nasconde questa loro vera natura!&lt;br /&gt;
Possiamo sapere i valori dei parametri passati all&#39;invocazione della funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function test() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var s = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;for(var i=0;i&amp;lt;arguments.length;i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; var arg = arguments[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; s += arg+&quot; &quot;+typeof(arg)+&quot;\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(s);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;test(&quot;text&quot;, 2, function(){alert(&quot;hello&quot;)}, 2.5);&lt;/span&gt;&lt;br /&gt;
E infine, come vedremo nelle sezioni successive, possiamo instanziare un oggetto usando una funzione&lt;br /&gt;
come costruttore:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function Test() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;//code&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; return 5;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = new Test();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var b = Test();&lt;/span&gt;&lt;br /&gt;
Ma attenzione, la variabile &lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;a&lt;/span&gt;&lt;/i&gt; conterrà un riferimento all&#39;instanza di un oggetto che avrà eventuali proprietà e metodi definiti secondo quanto spiegato nelle sezioni successive, mentre &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;b&lt;/i&gt;&lt;/span&gt; conterrà il valore numerico &quot;5&quot;.&lt;br /&gt;
Verificate &amp;nbsp;con un &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(a)&lt;/span&gt; e un &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(b)&lt;/span&gt; ;)&lt;br /&gt;
In entrambi i casi la funzione Test verrà eseguita.&lt;br /&gt;
Inoltre anticipo che lo scope della funzione cambia, cioè il riferimento &lt;i&gt;this&lt;/i&gt; usato all&#39;interno si riferirà all&#39;oggetto che stiamo instanziando &lt;i&gt;a&lt;/i&gt;, altrimenti all&#39;oggetto contenitore (per esempio window per &lt;i&gt;b&lt;/i&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Singleton&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Incominciamo con la creazione di un instanza al volo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = {}&lt;/span&gt;&lt;br /&gt;
oppure&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = new Object();&lt;/span&gt;&lt;br /&gt;
Abbiamo assegnato alla variabile &lt;i&gt;obj&lt;/i&gt; un&#39;instanza di un oggetto senza definire proprietà e metodi.&lt;br /&gt;
Certo, così non ci serve a niente. aggiungiamogli una proprietà:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;obj.prop1 = &quot;property 1&quot;;&lt;/span&gt;&lt;br /&gt;
oppure potevamo definirla direttamente dentro l&#39;instanza con la sintassi &lt;i&gt;propertyName:value&lt;/i&gt; (per più proprieta utilizzare la virgola come separatore)&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = { prop1:&quot;property 1&quot; };&lt;/span&gt;&lt;br /&gt;
Proviamo a visualizzarla su un alert:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( obj.prop1 );&lt;/span&gt;&lt;br /&gt;
Creiamo ora un metodo alla nostra istanza che visualizza sull&#39;alert il valore prop1:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;obj.alertProp1 = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert( this.prop1 );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
o in alternativa:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;prop1:&quot;property 1&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alertProp1:&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function() {&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;alert( this.prop1 );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;};&lt;/span&gt;&lt;br /&gt;
Per eseguire il metodo appena creato:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;obj.alertProp1();&lt;/span&gt;&lt;br /&gt;
C&#39;è ancora un&#39;altra alternativa per accedere a tutte le proprietà e metodi del nostro oggetto:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( &lt;b&gt;obj[&#39;prop1&#39;]&lt;/b&gt; );&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
cioè il nome della proprietà è la chiave per accedere al suo valore con la stessa sintassi di un array.&lt;br /&gt;
Possiamo così anche ciclare tutte le proprietà di un oggetto:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var s = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var p in obj) &amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; s += p + &quot;=&quot; + obj[p] + &quot; (&quot; + typeof(obj[p]) &amp;nbsp;+ &quot;)\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert(s);&lt;/span&gt;&lt;br /&gt;
Creare in questa maniera un singleton, può essere interessante se vogliamo definire, per esempio, una serie di proprietà da passare ad una funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var mySetup = {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;color: &quot;yellow&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;backcolor: &quot;black&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;text: &quot;hello&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;border: 1,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;click: function(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;clicked&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function createLabel(setup) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; setup = setup || {}; //se non mi viene passato il parametro ne creo uno nuovo&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var e = document.createElement(&quot;div&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; e.appendChild( document.createTextNode(setup.text || &quot;&quot; ) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; e.style.color = setup.color || &quot;black&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; e.onclick = setup.click;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; // etc... &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; return e;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var label = createLabel(mySetup),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
Notate che se non aggiungete metodi al vostro singleton, abbiamo l&#39;equivalente di una hashmap o array associativo.&lt;br /&gt;
A proposito di array, dimenticavo che potete aggiungere alle proprietà del vostro oggetto:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; prop1: &quot;property 1&quot;,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alertProp1: function(){ &amp;nbsp;alert(this.prop1); },&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; arr: [1, &quot;2&quot;, &amp;nbsp;3 ]&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( obj.arr[1] );&lt;/span&gt;&lt;br /&gt;
La proprietà &lt;i&gt;arr&lt;/i&gt; è quindi un riferimento ad un oggetto di tipo array che ha quindi proprietà tipo &lt;i&gt;length&lt;/i&gt;. &lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;for(var i=0; i&amp;lt;obj.arr.length; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var item = obj.arr[i];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(item);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Un modo alternativo per definire un singleton, e che io personalmente preferisco è questo:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var obj = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var me = {};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; me.myPublicProperty = &quot;hello&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;me.myPublicMethod = function(myparam) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//.....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var myPrivateMethod = function(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var myPrivateProperty = &quot;world&quot;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; return me;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;b&gt;()&lt;/b&gt;;&lt;/span&gt;&lt;br /&gt;
Notate che mettendo le parentesi tonde alla fine la funzione viene subito eseguita. La funzione restituisce un&#39;instanza di un oggetto con metodi e proprietà.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Classe&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Passiamo ora a come definire una classe.&lt;br /&gt;
Proviamo a creare una semplice classe che conta il numero di click su un elemento:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var ClickCounter = function(id) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var el = document.getElementById(id);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;this.counter&lt;/span&gt; = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var me = this;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; el.onclick = function(){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.counter++;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;this.show&lt;/span&gt; = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert( this.counter );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;In questa classe abbiamo definito una proprietà&amp;nbsp;&lt;i&gt;count&lt;/i&gt;&amp;nbsp;e un metodo&amp;nbsp;&lt;i&gt;show.&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Si rimanda alla sezione successiva per un chiarimento sullo &lt;i&gt;scope&lt;/i&gt; (contesto) e la visibilità delle variabili.&lt;br /&gt;
Possiamo definire una classe anche con questa forma:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ClickCounter&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(id) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var el = document.getElementById(id);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.count = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var me = this;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; el.onclick = function(){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.count++;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.show = function() {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert( this.counter );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Come in altri linguaggi l&#39;oggetto si instanzia con &quot;new&quot;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var cc = new ClickCounter(&quot;myButton1&quot;);&lt;/span&gt;&lt;br /&gt;
Ma allora vi chiederete a cosa si riferisce &lt;i&gt;this&lt;/i&gt; se &amp;nbsp;ci limitiamo a chiamare i costruttore senza &lt;i&gt;new&lt;/i&gt;.&lt;br /&gt;
&lt;u&gt;Si riferisce all&#39;oggetto contenitore.&lt;/u&gt;&lt;br /&gt;
Proviamo a fare un test;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function ShowCiao() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;this.alert(&quot;ciao&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Se chiamamo la funzione:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ShowCiao();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
ci viene mostrato un alert perchè &lt;i&gt;this&lt;/i&gt; si riferisce all&#39;oggetto &lt;i&gt;window &lt;/i&gt;che è il contenitore di tutti gli oggetti creati nell&#39;ambito di una pagina web.&lt;br /&gt;
Mentre con&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;new ShowCiao();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
non viene mostrato l&#39;alert perchè &lt;i&gt;this&lt;/i&gt; si riferisce all&#39;istanza di ShowCiao che non ha il metodo &lt;i&gt;alert&lt;/i&gt;. Questo genererebbe un errore javascript.&lt;br /&gt;
Un&#39;altro modo per creare un istanza di un oggetto è questo:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var myObjFactory = function(msg) {&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;var me = {};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; me.myPublicProperty = msg;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;me.myPublicMethod = function(myparam) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//.....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var myPrivateMethod = function(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var myPrivateMethod = &quot;world&quot;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; return me;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Praticamente è la stessa funzione che abbiamo visto nella sezione &quot;Singleton&quot;, ma senza le parentesi tonde.&lt;br /&gt;
Per creare un&#39;istanza è quindi sufficiente eseguire la funzione:&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var myObj1 = myObjFactory(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;var myObj2 = myObjFactory(&quot;ciao&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Visibilità e scope della variabili&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Riferiamoci sempre all&#39;esempio precedente, la classe &lt;i&gt;ClickCounter&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
All&#39;interno del costruttore abbiamo dichiarato due variabili:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;this.count = 0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
e&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementBy(id);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La differenza è che anteponendo &lt;i&gt;this&lt;/i&gt; alla variabile questa è accessibile all&#39;esterno, mentre con &lt;i&gt;var&lt;/i&gt; è visibile solo all&#39;interno del contenitore comprese sotto classi/funzioni. Praticamente è come dichiararla &lt;i&gt;private&lt;/i&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Inoltre abbiamo creato una terza variabile &lt;i&gt;private&lt;/i&gt;:&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var me = this;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
A questo punto vi chiederete perchè nella funzione di &lt;i&gt;onclick&lt;/i&gt; ho usato &lt;i&gt;me&lt;/i&gt; mentre per la funzione &lt;i&gt;show&lt;/i&gt; ho potuto utilizzare &lt;i&gt;this&lt;/i&gt; per riferirmi all&#39;instanza della classe &lt;i&gt;ClickCounter&lt;/i&gt;.&lt;br /&gt;
Nell&#39;assegnazione&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.onclick = function(){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.counter++;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
se avessimo usato &lt;i&gt;this&lt;/i&gt;&amp;nbsp;ci saremmo riferiti all&#39;oggetto contenitore&amp;nbsp;&lt;i&gt;el&lt;/i&gt; che possiede appunto la proprietà &lt;i&gt;onclick&lt;/i&gt;. Lo &lt;i&gt;scope&lt;/i&gt; della funzione quando invocata dal bowser è &lt;i&gt;el&lt;/i&gt;, non il mio oggetto &lt;i&gt;ClickCounter&lt;/i&gt;. Quindi &lt;i&gt;this&lt;/i&gt;&amp;nbsp;all&#39;interno della funzione handler di onclick si riferisce ad &lt;i&gt;el&lt;/i&gt;.&lt;br /&gt;
Mentre &lt;i&gt;show&lt;/i&gt; è una proprietà di &lt;i&gt;ClickCounter&lt;/i&gt;, quindi &lt;i&gt;this&lt;/i&gt; si riferisce ad una sua istanza.&lt;/div&gt;
&lt;div&gt;
Possiamo utilizzare &lt;i&gt;me&lt;/i&gt; all&#39;interno della funzione di &lt;i&gt;onclick &lt;/i&gt;perchè &amp;nbsp;ogni variabile dichiarata con &lt;i&gt;var&lt;/i&gt;&amp;nbsp;a livello superiore è visibile a livello più interno.&lt;br /&gt;
Per esempio:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var a = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc; color: #cc0000;&quot;&gt;alert( a ); //show &quot;1&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function TestClass() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var b = 2;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc;&quot;&gt;alert( a ); //show &quot;1&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc;&quot;&gt;alert( b ); //show &quot;2&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;function innerFunc() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var c = 3;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc;&quot;&gt;&amp;nbsp;alert( a ); //show &quot;1&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc;&quot;&gt;alert( b ); //show &quot;2&quot;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #cccccc;&quot;&gt;alert( c ); //show &quot;3&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;alert( c ); //show &quot;&lt;i&gt;&lt;b&gt;undefined&lt;/b&gt;&lt;/i&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow; color: #cc0000;&quot;&gt;alert( b ); //show &quot;&lt;b&gt;&lt;i&gt;undefined&lt;/i&gt;&lt;/b&gt;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow; color: #cc0000;&quot;&gt;alert( c ); //show &quot;&lt;b&gt;undefined&lt;/b&gt;&quot;&lt;/span&gt;&lt;br /&gt;
Inoltre in ogni sotto funzione sono visibili anche i parametri passati come argomento al costruttore di &lt;i&gt;ClickCounter&lt;/i&gt;.&lt;/div&gt;
&lt;/div&gt;
Per esempio &amp;nbsp;aggiungiamo &amp;nbsp;un &lt;i&gt;alert&lt;/i&gt;&amp;nbsp;che mostra il parametro &lt;i&gt;id&lt;/i&gt; passato al costruttore:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ClickCounter&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;id&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var el = document.getElementById(id);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.count = 0;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var me = this;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; el.onclick = function(){&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.count++;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;id&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.show = function() {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert( this.counter );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
Questo ci permette un trucco per passare parametri ad una funzione che per esempio non ne prevede.&lt;br /&gt;
Mi spiego meglio con un esempio pratico.&lt;br /&gt;
Assegno un handler all&#39;evento onclick di un elemento DOM:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;id);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.onclick = function(event){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; document.getElementById(&quot;showContainer&quot;).innerHTML = &quot;clicked&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
La mia funzione verrà chiamata dal browser sul &lt;i&gt;click&lt;/i&gt; del mio elemento &lt;i&gt;el&lt;/i&gt; e mostrerà il messaggio all&#39;interno di un div con &lt;i&gt;id=&quot;showContainer&lt;/i&gt;&quot;;&lt;br /&gt;
Ma se usassi la stessa funzione come &lt;i&gt;handler&lt;/i&gt; da assegnare a più elementi, potrei avere la necessita di passare altri parametri da visualizzare nel &lt;i&gt;div&lt;/i&gt; mentre l&#39;unico parametro che il browser mi passerà è solo l&#39;oggetto &lt;i&gt;event&lt;/i&gt;.&lt;br /&gt;
Dunque è possibile risolvere la questione creando un factory&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;createClickHandler&lt;/span&gt;&amp;nbsp;e sfruttando la visibilità dei parametri passati.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var createClickHandler = function(&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;message&lt;/span&gt;) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return function(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;document.getElementById(&quot;showContainer&quot;).innerHTML = &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;message&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;id1&quot;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;.onclick = createClickHandler(&quot;clicked on element 1&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;id2&quot;)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;.onclick = createClickHandler(&quot;clicked on element 2&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Variabili static&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Utilizzo il termine &lt;i&gt;static&lt;/i&gt; in analogia con la programmazione JAVA intendendo variabili accessibili senza utilizzare un instanza.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var MyClass = function(prop) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.prop = prop; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Definisco così una proprietà static:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;MyClass.&lt;b&gt;staticProp&lt;/b&gt; = &quot;static proprerty&quot;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Attenzione però, questa proprietà non è accessibile da una instanza (per un chiarimento vedere la sezione&amp;nbsp;&quot;approfondimento&quot; alla fine di questo tutorial):&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var o = new MyClass(prop);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( o.staticProp ); //show undefined&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Mentre è accessibile in questo modo:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( MyClass.staticProp );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Prototype&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Precedentemente per aggiungere proprietà e motodi alla nostre classi, abbiamo usato il riferimento &lt;i&gt;this&lt;/i&gt; all&#39;interno del nostro costruttore.&lt;br /&gt;
In alternativa avremmo potuto usare il metaoggetto &lt;i&gt;prototype&lt;/i&gt; che contiene tutti i riferimenti a proprietà e metodi precedentemente definiti e consente di aggiungerne di nuovi.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var&amp;nbsp;MyClass&amp;nbsp;= functon(prop) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.prop = prop; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var privateProp = prop;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;MyClass.prototype.showProp = function(){&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(this.prop);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(privateProp); &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
Notate che nel metodo showProp possiamo accedere alla proprietà &lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;prop&lt;/span&gt;&lt;/i&gt; tramite &lt;i&gt;this&lt;/i&gt; ma non possiamo accedere a &lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;privateProp&lt;/span&gt;&lt;/i&gt;. (Neanche con this.privateProp).&lt;br /&gt;
Con &lt;i&gt;prototype&lt;/i&gt; possiamo anche sovrascrivere un metodo esistente.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;Ereditarietà&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Infine concludiamo il discorso prototype per ereditare proprietà e metodi da un&#39;altra classe:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var BaseClass = function() {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;this.counter = 0;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;this.incr10 = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.counter +=10&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var ExtClass = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.incr20 = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.counter += 20;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ExtClass.prototype = new BaseClass(); //eredita metodi e proprietà di BaseClass&lt;/span&gt;&lt;br /&gt;
Se vi sembra un po&#39; strano passare una nuova istanza piuttosto che il nome della classe, riguardate la sezione approfondimenti. Almeno intuitivamente dovrebbe esser chiaro che non ha senso passare solo ExtClass che è un riferimento ad un oggetto di tipo function. Significherebbe ereditare proprietà e metodi di un oggetto Function.&lt;br /&gt;
Se al posto della classe BaseExt avessimo definito un singleton:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var baseObj = {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; count: 0,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; incr10: function() { this.count +=10; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
avremmo potuto scrivere:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ExtClass.prototype = baseObj;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Se vogliamo utilizzare il costruttore di ExtClass al posto di quello di BaseClass.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;ExtClass.prototype.constructor = ExtClass;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
In questo caso ha senso passare come costruttore il riferimento ad una instanza di una funzione.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;i&gt;Estendere una classe&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Abbiamo gia visto con &quot;prototype&quot; come far ereditare metodi e proprietà di un&#39;altra classe.&lt;br /&gt;
E&#39; possibile farlo anche in questo modo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var Class1 = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.method1 = function() { alert(&quot;method class 1&quot;) }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.prop1 = &quot;p1&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var Class2 = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;background-color: yellow;&quot;&gt;Class1.call(this);&lt;/span&gt;&amp;nbsp;//&lt;i&gt;extends class1&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.method2 = function () {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //....&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = new Class2();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;obj.method1(); //&lt;i&gt;utilizziamo il metodo ereditato dal Class1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;i&gt;Cenni sull&#39;oggetto window&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
E&#39; un oggetto che viene instanziato automaticamente dal browser quando viene caricata una nuova pagina.&lt;br /&gt;
E&#39; l&#39;oggetto contenitore di tutti i nostri oggetti, infatti se create una nuova proprietà di &lt;i&gt;window&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;window.myprop = &quot;property&quot;;&lt;/span&gt;&lt;br /&gt;
Questa sarà visibile in ogni sottofunzione e oggetto da noi creato.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Per questo se creiamo una funzione:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function show(message){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;this&lt;/span&gt;.alert(message);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;show(&quot;hello&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;this&lt;/i&gt; si riferisce all&#39;oggetto&amp;nbsp;&lt;i&gt;window&lt;/i&gt;, in quanto lo&amp;nbsp;scope della funzione&lt;i&gt; show&lt;/i&gt;.&lt;/div&gt;
&lt;br /&gt;
L&#39;oggetto &lt;i&gt;window&lt;/i&gt; ci consente di accedere al &lt;i&gt;DOM&lt;/i&gt; (document object model) per poter interagire con la nostra pagina via javascript:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;window.document.getElementById(&quot;id&quot;);&lt;/span&gt;&lt;br /&gt;
ma possiamo accedervi direttamente senza utilizzare il riferimento &lt;i&gt;window&lt;/i&gt;:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;id&quot;);&lt;/span&gt;&lt;br /&gt;
perchè esiste una variabile implicita&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;var document = window.document;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Anche la funzione alert è un metodo di window&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;window.alert(&quot;hello&quot;);&lt;/span&gt;&lt;br /&gt;
con il riferimento diretto implicito:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;var alert = window.alert&lt;/i&gt;;&lt;/span&gt;&lt;br /&gt;
Ci sono tanti altri oggetti importanti che sono proprietà di &lt;i&gt;window&lt;/i&gt; come per esempio&amp;nbsp;&lt;i&gt;history&lt;/i&gt; e&amp;nbsp;&lt;i&gt;location&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-decorations-in-effect: none;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;Approfondimento&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Il concetto di classe non è propriamente lo stesso dei linguaggi come Java, perchè non possiamo definire una classe, ma semmai un oggetto costruttore che esegue istruzioni che vanno ad arricchire di proprietà e metodi un oggetto vuoto, quello che stiamo istanziando.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Possiamo comunque&amp;nbsp;testare se una certo oggetto è stato generato tramite una cerca funzione mediante l&#39;operatore&amp;nbsp;&lt;i&gt;instanceof&lt;/i&gt;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function Test(){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var t = new Test();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( t&amp;nbsp;&lt;b&gt;instanceof&lt;/b&gt;&amp;nbsp;Test );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Dato che&amp;nbsp;&lt;i&gt;Object&lt;/i&gt;&amp;nbsp;è la classe di base di ogni oggetto, verrà visualizzato&amp;nbsp;&lt;i&gt;true&lt;/i&gt;&amp;nbsp;anche per :&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( t&amp;nbsp;&lt;b&gt;instanceof&lt;/b&gt;&amp;nbsp;Object );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Se avessimo usato la funzione&amp;nbsp;&lt;i&gt;typeof&lt;/i&gt;, avremmo ottenuto sempre &quot;object&quot;:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(t)&amp;nbsp;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Ma per chiarire il concetto di classe in javascript, mi riferirò all&#39;esempio della &amp;nbsp;sezione&amp;nbsp;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;variabili&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&amp;nbsp;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;static&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La proprietà&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;staticProp&lt;/span&gt;&lt;/i&gt;&amp;nbsp;non è una variabile statica di una classe&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;MyClass&lt;/i&gt;&lt;/span&gt;&amp;nbsp; ma è una proprietà dell&#39;oggetto&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;MyClass&lt;/i&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
infatti con l&#39;istruzione:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;alert( typeof(MyClass) );&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
vi verrà mostrato &quot;function&quot;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Se vi ricordate quanto visto nella sezione&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;i&gt;&lt;b&gt;function&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;, la variabile&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;MyClass&lt;/i&gt;&lt;/span&gt;&amp;nbsp;è un riferimento ad un istanza di&amp;nbsp;&lt;i&gt;function&lt;/i&gt;, quindi è un oggetto di tipo&amp;nbsp;&lt;i&gt;function&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
A questo oggetto ho aggiunto una proprietà che ho chiamato&amp;nbsp;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;staticProp&lt;/span&gt;&lt;/i&gt;&amp;nbsp;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Per questo non esiste &amp;nbsp;la proprietà&amp;nbsp;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;o.staticProp&lt;/span&gt;&lt;/i&gt;&amp;nbsp;perche è la proprietà di un altro oggetto appunto.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
In altre parole tramite il termine &quot;&lt;i&gt;new&lt;/i&gt;&quot; viene creato un oggetto invocando l&#39;esecuzione di un oggetto&amp;nbsp;&lt;i&gt;function&lt;/i&gt;. Ma questi due oggetti non condividono proprietà e metodi.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Quindi ricapitolando la creazione di un oggetto può avvenire in due maniere.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Tramite sintassi&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;var obj = { pro1:val1, prop2:val2, .... }&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
oppure&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;var obj = new ( new Function(params, body)).&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;call(this=refNewObj,myParams);&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La seconda versione ci consente di utilizzare lo stesso oggetto function per creare più oggetti con uguali proprietà e metodi tramite l&#39;invocazione implicita del suo metodo&amp;nbsp;&lt;i&gt;call&lt;/i&gt;. Il riferimento&amp;nbsp;&lt;i&gt;this&lt;/i&gt;&amp;nbsp;si riferisce all&#39;oggetto contenitore, in questo caso all&#39;oggetto che stiamo creando.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
La sintassi&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;i&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = new MyObj();&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
potremmo interpretarla come se il termine&amp;nbsp;&lt;i&gt;new&lt;/i&gt;&amp;nbsp;instanziasse un oggetto vuoto&lt;i&gt;&amp;nbsp;{}&lt;/i&gt;&amp;nbsp;e come se il termine&amp;nbsp;&lt;i&gt;MyObj()&lt;/i&gt;&amp;nbsp;eseguisse la funzione che arricchisce di metodi e proprietà il nostro oggetto&amp;nbsp;&lt;i&gt;{}&amp;nbsp;&lt;/i&gt;il cui riferimento viene assegnato alla variabile&amp;nbsp;&lt;i style=&quot;background-color: white;&quot;&gt;obj&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Infatti è equivalente a:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj = {};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;MyObj.call(obj);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
nell&#39;argomento del metodo call abbiamo passato il riferimento all&#39;oggetto obj come contesto(scope) per il riferimento&amp;nbsp;&lt;i&gt;this&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Questo ci fa capire anche che una funzione può essere il costruttore/inizializzatore di diversi oggetti, basta passargli lo scope (il riferimento all&#39;istanza) diverso:&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var f = function(){ this.prop3 = &quot;p3&quot;; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj1 = {prop1:&quot;p1&quot;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;f.call(obj1);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var obj2 = {prop2:&quot;p2&quot;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;f.call(obj2);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/17319267053394857/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/17319267053394857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/17319267053394857'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/06/javascript-programmazione-ad-oggetti.html' title='javascript programmazione ad oggetti'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-4338531437630576168</id><published>2011-05-27T09:45:00.011+02:00</published><updated>2011-07-25T23:12:50.297+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="skype"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu 11.04"/><title type='text'>UBUNTU 11.04 skype  crashes, non parte più, non funziona</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;http://translate.google.com/translate?u=http://gheryd.blogspot.com/2011/05/ubuntu-1104-skype-crashes-non-parte.html&amp;amp;sl=it&amp;amp;tl=en&amp;amp;hl=it&quot;&gt;english version&lt;/a&gt;&lt;br /&gt;
Il 27 maggio 2011 skype non si avviava più&lt;br /&gt;
Ho risolto rimuovendo il file shared.xml di skype. (nell&#39;esempio sotto l&#39;ho rinominato)&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: black; color: white;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;mv .Skype/shared.xml .Skype/shared.xml.bkp&lt;/b&gt;
gheryd@gheryd-laptop:~$ &lt;b&gt;skype &amp;amp;&lt;/b&gt;
&lt;/pre&gt;&lt;br /&gt;
(La tilde sta per cartella home).&lt;br /&gt;
&lt;br /&gt;
Quando poi riavviate skype, compare la pagina di licenza. Date l&#39;ok e skype ritornerà in vita. :)&lt;br /&gt;
&lt;br /&gt;
Se non vi compare l&#39;icona sulla tray bar date un&#39;occhiata al seguente post:&lt;br /&gt;
&lt;a href=&quot;http://gheryd.blogspot.com/2011/05/ubuntu-skype-icon-nascosta-hidden.html&quot;&gt;http://gheryd.blogspot.com/2011/05/ubuntu-skype-icon-nascosta-hidden.html&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/4338531437630576168/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/05/ubuntu-1104-skype-crashes-non-parte.html#comment-form' title='8 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4338531437630576168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4338531437630576168'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/05/ubuntu-1104-skype-crashes-non-parte.html' title='UBUNTU 11.04 skype  crashes, non parte più, non funziona'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-5667702286657904543</id><published>2011-05-22T14:30:00.077+02:00</published><updated>2011-08-11T00:20:11.569+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>javascript  funzioni browser compatibili (cross browser) per gli eventi</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-decorations-in-effect: none; font-size: small; font-style: normal;&quot;&gt;Indice dei tutorials:&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&quot;&gt;http://gheryd.blogspot.com/2011/06/javascript-gwt-tutorials.html&lt;/a&gt;&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;u&gt;Indice:&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Funzioni per la compatibilità&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Registrare una funzione handler dll&#39;evento&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Lista eventi&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Registrare lo stesso handler per più eventi&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Eventi da tastiera&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Tasti speciali&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Esempio completo: currency text box&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Handler in html&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Passare parametri all&#39;handler&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Esempio completo: editable table&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Eventi onload e onerror immagini&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Gestire il submit del form&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;u&gt;Introducendo&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;In questo tutorial mi propongo di spiegare come utilizzare gli eventi DOM con particolare attenzione su casi critici i cui mi sono imbattuto nel mio lavoro di sviluppo e che ho risolto cercando in giro per il web.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Non mi soffermo troppo sulle spiegazioni ma credo che gli esempi siano sufficientemente chiari. Se avete dubbi, correzioni o suggerimenti commentate!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;Questo post verrà continuamente aggiornato con altri interessanti spunti e esempi.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Funzioni per la compatibilità&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Prima di iniziare introduco tre funzioni che ci garantiranno negli esempi js che seguono la compatibilità con i vari browser:&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;function &lt;b&gt;ensureEvent&lt;/b&gt;(e) {&amp;nbsp;return !e ? e = window.event : e; }&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;function &lt;b&gt;getElementByEvent&lt;/b&gt;(e) { return (e.target) ? e.target : e.srcElement&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;function&amp;nbsp;&lt;b&gt;getKeyByEven&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&lt;b&gt;t&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;(e)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;{&amp;nbsp;return e.keyCode ? e.keyCode : e.charCode;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;Registrare una funzione handler dell&#39;evento&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;Per settare un handler che tratti uno specifico evento è sufficiente procedere nella maniera seguente&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var el = document.getElementById(&quot;idEl&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el.onclick = function(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;alert(&quot;clicked!&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Ogni volta che si clicca sull&#39;elemento che ha l&#39;attributo id=&quot;idEL&quot; verrà visualizzato un alert.&lt;br /&gt;
Da html sarebbe analogo a:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;button &amp;nbsp;onclick=&quot;alert(&#39;clicked&#39;)&quot;&amp;gt;click me&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;div onclick=&quot;alert(&#39;clicked&#39;)&quot;&amp;gt;...&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;a href=&quot;#&quot; &amp;nbsp;onclick=&quot;alert(&#39;clicked&#39;);return false&quot;&amp;gt;click me&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;
Il return false annulla &amp;nbsp;l&#39;eventuale azione su href (il browser non apre la pagina sull&#39;url specificato). In caso contrario mettere un return true.&lt;br /&gt;
Comunque negli esempi successivi agganceremo gli handlers via javascript, che è utile soprattutto se si creano elementi dinamicamente:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var button = &amp;nbsp;document.createElement(&quot;button&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;button.setAttribute(&quot;id&quot;, &quot;mybutton&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;button.className = &quot;buttonClass&quot;; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc;&quot;&gt;//la classe di stile non si può settare tramite setAttribute&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;button.appendChild( document.createTextNode(&quot;click me&quot;) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;button.onclick = fuction() { alert(&quot;clicked&quot;); };&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;container&quot;).appendChild(button);&lt;/span&gt;&lt;br /&gt;
la funzione handler dell&#39;evento si può dichiarare anche a parte:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function onClickHandler(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;clicked&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
quindi assegnamo la funzione dichiarata in questo modo:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;button.onclick = onClickHandler;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;Lista eventi&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
E&#39; possibile registrare funzioni handler su svariati eventi. Alcuni tag html supportano solo alcuni degli eventi di seguito elencati.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onclick&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;ondblclick&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onkeyup&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onkeypress&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onkeydown&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onblur&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onfocus&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onmouseover&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onmousedown&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onmouseup&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onmouseout&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onmousemove&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onchange&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onselect&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onresize&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onload&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onload&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;element.&lt;b&gt;onerror&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Potrebbe mancare qualche evento, comunque quelli più usati ci sono.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;Registrare lo stesso handler per più elementi&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Nell&#39;esempio seguente registriamo lo stesso handler su più elementi.&lt;br /&gt;
Questo potrebbe essere interessante se avete una funzione di validazione che potete utilizzare su più campi text, per esempio. Oppure a cambiare colore di sfondo sul mouseout o il mouseover.&lt;br /&gt;
Qui mi limito a mostrare un alert con informazioni relative all&#39;elemento alla perdita del focus:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onBlurHandler&lt;/b&gt;(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;event = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;ensureEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;vat el =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;getElementByEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var tagname = el.tagName;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var id = el.getAttribute(&quot;id&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var value = el.value;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;tagname: &quot;+tagname+&quot;\n&quot;+&quot;id: &quot;+id+&quot;\n&quot;+&quot;value: &quot;+value);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;input1&quot;).onblur =&amp;nbsp;onBlurHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;input2&quot;).onblur =&amp;nbsp;onBlurHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;input3&quot;).onblur =&amp;nbsp;onBlurHandler;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Eventi da tastiera&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Proviamo ora la gestione degli eventi da tastiera.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var ctrl = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onKeyDownHandler&lt;/b&gt;(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;event = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;ensureEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var unicode = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;getKeyByEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var msg = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if( unicode == 17 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ctrl &amp;nbsp;= &quot;ctrl + &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }else {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;msg = ctrl + unicode;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;document.getElementById(&quot;messageContainer&quot;).innerHTML = msg;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onKeyUpHandler&lt;/b&gt;(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;event = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;ensureEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var unicode = &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;getKeyByEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;if( unicode == 17 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ctrl = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;idInput&quot;).onkeydown =&amp;nbsp;onKeyDownHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;idInput&quot;).onkeyup =&amp;nbsp;onKeyUpHandler;&lt;/span&gt;&lt;br /&gt;
L&#39;html da inserire per l&#39;esempio precedente è:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;input: &amp;lt;input id=&quot;idInput&quot; type=&quot;text&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;&amp;lt;div id=&quot;messageContainer&quot; &amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
Con l&#39;esempio sopra viene visualizzato nel div il codice unicode del tasto premuto. Indica inoltre l&#39;eventuale &amp;nbsp;combinazione con il tasto control (ctrl).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Tasti speciali&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Di particolare interesse sono i codici unicode di alcuni tasti speciali (senza corrispondente carattere):&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;var specialKey = {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;DEL&quot; : 8,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;TAB&quot; : 9,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;ENTER&quot; : 13,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;SHIFT&quot; : 16,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;CTRL&quot; : 17,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;ALT&quot; : 18,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;ESC&quot; : 27,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;SPACE&quot; : 32,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;PAGEUP&quot; : 33,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;PAGEDOWN&quot;: 34,&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;END&quot;: 35,&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;HOME&quot;, 36,&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;LEFT&quot; : 37,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;UP&quot;: 38,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;RIGHT&quot;: 39,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;DOWN&quot;: 40,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;INS&quot;: 45,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;CANC&quot;: 46,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;WINDOWS&quot;: 91,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;F1&quot;: 112,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &quot;F2&quot;: 113&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a64d79; font-size: x-small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Ecco un esempio di utilizzo di questa mappa dei tasti speciali all&#39;interno di un key handler:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;e.onkeydown = function(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;event =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;ensureEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold; white-space: pre;&quot;&gt;&amp;nbsp;   &lt;/span&gt;var unicode&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-weight: bold;&quot;&gt; =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;getKeyByEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; if( &lt;b&gt;unicode==specialKey.TAB&lt;/b&gt; ) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(event.preventDefault) event.preventDefault();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
L&#39;input text non perde così il focus premendo il tasto TAB.&lt;br /&gt;
&lt;br /&gt;
Possiamo anche utilizzare la mappa dei caratteri speciali per sapere se il tasto premuto è un carattere speciale:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;getSpecialKeyLabel&lt;/b&gt;(unicode) {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var label = null;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; for(var k in&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;specialKey&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;) {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if( unicode==&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;specialKey[&lt;/b&gt;k&lt;b&gt;]&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;){ label =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;k&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;break; } &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;return label;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;e.onkeydown = function(event)&amp;nbsp;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;event =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;ensureEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold; white-space: pre;&quot;&gt;&amp;nbsp;   &lt;/span&gt;var unicode&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-weight: bold;&quot;&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;getKeyByEvent&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(event);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var k =&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;getSpecialKeyLabel&lt;/b&gt;(unicode);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; if(!k) k = String.fromCharCode(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; alert(&quot;hai premuto il tasto &quot;+k);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Esempio completo: Currency Textbox&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;In questo esempio lavoriamo su un input text in maniera tale che gestica l&#39;inserimento di un dato numerico sul focus e visualizzi il valore formattato come valuta sul blur.&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;L&#39;unico carattere speciale che intercettiamo sul keypress è l&#39;enter (invio) corrispondente al unicode 13. Sempre su questo evento viene verificato l&#39;inserimento solo di numeri e separatore decimale (solo una volta).&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Inoltre ho aggiunto un accorgimento per il form. Ho inserito un campo nascosto con name=&quot;price&quot;. La text box non ha l&#39;attribute name perchè non voglio &quot;submittare&quot; sul server un valore formattato, ma solo il puro valore numerico che viene settato sul campo nascosto prima del submit.(vedi funzione &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;onSubmitHandler&lt;/span&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e69138;&quot;&gt;function ensureEvent(e) { return !e ? e = window.event : e; }&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e69138;&quot;&gt;function getElementByEvent(e) { return (e.target) ? e.target : e.srcElement }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e69138;&quot;&gt;function getKeyByEvent(e) { return e.keyCode ? e.keyCode : e.charCode; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;CurrencyTextBox&lt;/b&gt;(textBoxId) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var me = this;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var number = 0.0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.el = document.getElementById( textBoxId );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.currencySymbol = &quot;E &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.&lt;b&gt;getNumber&lt;/b&gt; = function() { return number; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.&lt;b&gt;setNumber&lt;/b&gt; = function(n) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n = parseFloat(n); &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; number = isNaN(n) ? 0.0 : n;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; showFormatted();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; if( !this.el || this.el.tagName!=&quot;INPUT&quot;) throw &quot;element is not input&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.el.onkeypress = function(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; event = ensureEvent(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var unicode = getKeyByEvent(event);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(unicode==13){ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.el.blur();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(event.preventDefault) event.preventDefault();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var c = String.fromCharCode(unicode);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(&quot;1234567890.&quot;.indexOf(c)==-1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(event.preventDefault) event.preventDefault();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }else if(c==&quot;.&quot; &amp;amp;&amp;amp; me.el.value.indexOf(&quot;.&quot;)&amp;gt;-1) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(event.preventDefault) event.preventDefault();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.el.onblur = function(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.setNumber( me.el.value );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; this.el.onfocus = function(event) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; showNumber();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var showFormatted = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var v = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var nn = number.toString().split(&quot;.&quot;, 2);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var intn = parseInt(nn[0],10);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( isNaN(intn) ) intn = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var intv = intn+&quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(var i=intv.length-1;i&amp;gt;=0;i--) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var j = intv.length-i-1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(j&amp;gt;0 &amp;amp;&amp;amp; j%3==0) v = &quot;.&quot;+v; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; v = intv[i]+v;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; v += &quot;,&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( !nn[1] &amp;nbsp;||&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;nn[1]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;.length==0&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;) v += &quot;00&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&amp;nbsp;if( nn[1].length==1 ) v += nn[1]+&quot;0&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if( nn[1].length&amp;gt;2 ) v += nn[1].substring(0,2);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else v += nn[1];&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.el.value = me.currencySymbol+v;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; var showNumber = function() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; me.el.value = number;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;onSubmitHandler&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;(){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; document.getElementById(&quot;price&quot;).value = currencyTB.getNumber();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; document.getElementById(&quot;myForm&quot;).submit();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var currencyTB = null;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onLoadBodyHandler&lt;/b&gt;(){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; currencyTB = new CurrencyTextBox(&quot;currencyTB&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; currencyTB.setNumber(100);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body onLoad = &quot;&lt;b&gt;onLoadBodyHandler&lt;/b&gt;()&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form id=&quot;myForm&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price: &amp;lt;input id=&quot;currencyTB&quot; type=&quot;text&quot; style=&quot;text-align:right&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;input type=&quot;hidden&quot; name=&quot;price&quot; id=&quot;price&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;br/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;button onClick=&quot;&lt;b&gt;onSubmitHandler&lt;/b&gt;();&quot;&amp;gt;submit&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;Handler in innerHTML&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
E&#39; bene sapere che creare un tag con l&#39;attributo onclick (o qualsiasi altro evento) inserito via innerHMTL non fuziona per internet explorer (ie):&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var divEl = document.getElementById(&quot;container&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;divEl.innerHTML = &quot;&amp;lt;a href=&#39;#&#39; class=&#39;linkClass&#39; onClick=&#39;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffd966;&quot;&gt;&lt;b&gt;onClickHandler&lt;/b&gt;();return false;&lt;/span&gt;&#39;&amp;gt;click me!&amp;lt;/a&amp;gt;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #aa0000; border: 2px solid red; color: white; padding: 10px;&quot;&gt;&lt;b&gt;Non funziona su IE&lt;/b&gt;! &amp;nbsp;la funzione onClickHandler non viene chiamata. Questo vale per qualsiasi altro evento (es. mouseOver, mouseMove, mouseDown, etc).&lt;/div&gt;&lt;br /&gt;
Il codice corretto è:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;var linkEl = document.createElement(&quot;a&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;linkEl.setAttribute(&quot;href&quot;, &quot;#&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;linkEl.className = &quot;linkClass&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;linkEl.onclick = onClickHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;linkEl.appendChild( document.createTextNode(&quot;click me!&quot;) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;divEl.appendChild( linkEl );&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Passare parametri all&#39;handler&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Se occorresse passare uno o più parametri all&#39;handler:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;createClickHandler&lt;/b&gt;(&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;par1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;par2&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;) &lt;b&gt;{&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return function(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;par1:&quot;+&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;par1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;+&quot; par2:&quot;+&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;par2&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;}&lt;/b&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el1.onClick = createClickHandler(&quot;gheryd&quot;, 12345);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;el2.onClick = createClickHandler(&quot;pippo&quot;, 67890);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Esempio completo: Editable Table&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Segue un esempio più complesso che sfrutta il trucco sopra esposto.&lt;br /&gt;
Viene creata dinamicamente una tabella. Vari handlers vengono &amp;nbsp;agganciati a eventi &amp;nbsp;onclick, &amp;nbsp;onmouseover e onmouseout.&lt;br /&gt;
Sugli eventi del mouse cambia il colore della riga in cui si trova la cella mentre sull&#39;onclick appare un prompt per modificarne il contenuto.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;div style=&quot;color: #990000;&quot;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;createTable&lt;/b&gt;() &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var &lt;b&gt;createClickHandler&lt;/b&gt; = function(td, row, col) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return function(event)&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var v = prompt(&quot;inserire un nuovo valore per la cella &quot;+row+&quot;,&quot;+col, td.innerHTML);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(v) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.innerHTML = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.appendChild( document.createTextNode(v) );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var &lt;b&gt;createMouseOver&lt;/b&gt; = function(tr) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return function(event) {&amp;nbsp;tr.style.backgroundColor = &quot;yellow&quot;;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var &lt;b&gt;createMouseOut&lt;/b&gt; = function(tr) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return function(event) {&amp;nbsp;tr.style.backgroundColor = &quot;white&quot;;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var table = document.createElement(&quot;table&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;table.setAttribute(&quot;cellpadding&quot;, &quot;5px&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;table.setAttribute(&quot;border&quot;, &quot;1px&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;table.setAttribute(&quot;cellspacing&quot;, &quot;0&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;table.setAttribute(&quot;width&quot;, &quot;500px&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var tbody = document.createElement(&quot;tbody&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;table.appendChild(tbody);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;for(var r=0;r&amp;lt;10;r++) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var tr = document.createElement(&quot;tr&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(var c=0;c&amp;lt;5;c++) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var td = document.createElement(&quot;td&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.setAttribute(&quot;align&quot;, &quot;center&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.appendChild(document.createTextNode(r+&quot;,&quot;+c));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.onclick = &lt;b&gt;createClickHandler&lt;/b&gt;(td, r,c);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.onmouseover = &lt;b&gt;createMouseOver&lt;/b&gt;(tr);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; td.onmouseout = &lt;b&gt;createMouseOut&lt;/b&gt;(tr);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tr.appendChild(td);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tbody.appendChild(tr);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;document.body.appendChild(table);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;body onload=&quot;&lt;b&gt;createTable();&lt;/b&gt;&quot;&amp;gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
Migliorie: come esercizio potrebbe essere interessante sul click della cella inserire un input text al posto di far comparire il prompt. Sulla perdita del focus dell&#39;input, questo scomparirebbe e la cella verrebbe compilata con il nuovo valore.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;&lt;i&gt;&lt;u&gt;Eventi onload e onerror immagini&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Nell&#39;esempio seguente viene creato dinamicamente un elemento &amp;lt;image&amp;gt; e viene inserito all&#39;interno del contenitore div.&lt;br /&gt;
Se l&#39;immagine non esiste viene chiamato l&#39;handler per l&#39;evento &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;onerror&lt;/span&gt;, altrimenti verrà richiamato l&#39;handler per l&#39;evento &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;onload&lt;/span&gt; quando l&#39;immagine è stata caricata correttamente.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;html&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;head&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onLoadHandler&lt;/b&gt;(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;caricata&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onErrorHandler&lt;/b&gt;(event) &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;document.getElementById(&quot;cont&quot;).innerHTML = &quot;immagine non caricata&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function &lt;b&gt;onLoadBodyHandler&lt;/b&gt;() &lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;var img = new Image();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;img.onload = onLoadHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;img.onerror = onErrorHandler;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;document.getElementById(&quot;cont&quot;).appendChild(img);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp;img.src = &quot;img1.jpg&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;body onLoad=&quot;onLoadBodyHandler();&quot;&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;div id=&quot;cont&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;color: #999999;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;In questo esempio potrebbe essere interessante inserire un messaggio tipo &quot;loading...&quot; all&#39;interno del div finchè l&#39;immagine non è stata caricata (onload). Utile per immagini molto pesanti.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6; font-size: large;&quot;&gt;Gestire il submit del form&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
Tipicamente si vuole impedire o meno il submit del form in seguito &amp;nbsp;alla validazione dei campi.&lt;br /&gt;
Negli esempi che seguono ci riferiremo alla seguente funzione che restituisce un valore booleano &lt;i&gt;true&lt;/i&gt; se i campi del form sono validi, &lt;i&gt;false &lt;/i&gt;in caso contrario:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function validateForm() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var v = document.getElementById(&quot;myTextBox&quot;).value;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return v.length&amp;gt;0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
I tre seguenti esempi illustrano vari modi di gestire l&#39;evento di onsubmit del form.&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Esempio 1&lt;/i&gt;:&amp;nbsp;implementare l&#39;attributo onsubmit del tag form:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;form onsubmit=&quot;&lt;b&gt;return validateForm()&lt;/b&gt;&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;text&quot; name=&quot;fieldName&quot; id=&quot;myTextBox&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;button type=&quot;submit&quot; &amp;gt;submit&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
oppure si può registrare un handler via codice:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;document.getElementById(&quot;myForm&quot;).onsubmit = function(event){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(&amp;nbsp;validateForm()&amp;nbsp;) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}else {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;field is void&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Esempio 2&lt;/i&gt;:&amp;nbsp;implementare l&#39;evento onclick di un pulsante di tipo &quot;submit&quot;.&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;form id=&quot;myForm&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;text&quot; name=&quot;fieldName&quot; id=&quot;myTextBox&quot; /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;button type=&quot;&lt;b&gt;submit&lt;/b&gt;&quot; onclick=&quot;&lt;b&gt;return&amp;nbsp;onClickHandler()&lt;/b&gt;&quot;&amp;gt;submit&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function onClickHandler() {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if( validateForm() ) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }else {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;alert(&quot;field is void&quot;);&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Esempio 3&lt;/i&gt;: implementare l&#39;evento onclick di un pulsante di tipo &quot;button&quot;.&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;form id=&quot;myForm&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;text&quot; name=&quot;fieldName&quot; id=&quot;myTextBox&quot; /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;button type=&quot;&lt;b&gt;button&lt;/b&gt;&quot; onclick=&quot;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;onClickHandler()&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&quot;&amp;gt;submit&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function onClickHandler() {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if( validateForm() ) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;document.getElementById(&quot;myForm&quot;).&lt;b&gt;submit()&lt;/b&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }else {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;alert(&quot;field is void&quot;);&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
In questo esempio il pulsante di tipo &quot;button&quot; potrebbe essere sostituito da un &quot;div&quot; o da un link, cioè da qualsiasi oggetto html che può gestire l&#39;evento &quot;onclick&quot;.&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Conclusione&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;Anche se apparentemente i tre sistemi sopra illustrati possono sembrare equivalenti, in realtà c&#39;è una certa differenza.&lt;br /&gt;
Nell&#39;esempio 1 e 2 restituiamo un valore false per impedire il submit. Ma nel caso di errore javascript non viene impedito il submit del form.&lt;br /&gt;
Invece nell&#39;esempio 3 avviamo via codice il submit del form. In caso di errore javascript non viene eseguita l&#39;istruzione che effettua il submit.&lt;br /&gt;
Inoltre il metodo utilizzato nel terzo esempio può essere applicato per altri eventi al posto dell&#39;onclick.&lt;br /&gt;
Per esempio se volessimo avviare un timer che ritarda il submit del form, non potemmo applicare i metodi dell&#39;esempio 1 e 2:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;function onClickHandler() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var count = 3;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;var t = setInterval(function(){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;count--;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(count==0) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;document.getElementById(&quot;myForm&quot;).&lt;b&gt;submit()&lt;/b&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; }, 1000);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/5667702286657904543/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/5667702286657904543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/5667702286657904543'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/05/javascript-funzioni-compatibili-per-gli.html' title='javascript  funzioni browser compatibili (cross browser) per gli eventi'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-1468827038549619952</id><published>2011-05-21T19:36:00.009+02:00</published><updated>2011-05-22T22:14:25.943+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="php.ini"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>UBUNTU LINUX PHP configurare display log error</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Per chi sviluppa con php e necessita della visualizzazione degli errori sulle proprie pagine .php, è utile attivare sul file di configurazione &lt;b&gt;php.ini&lt;/b&gt; le opportune direttive che di default dovrebbero essere disattivate.&lt;br /&gt;
&lt;pre&gt;&lt;div style=&quot;background-color: black; color: white; padding: 10px;&quot;&gt;gheryd@gheryd-laptop:~$ &lt;b&gt;cd /etc/php5/apache2/&lt;/b&gt;
gheryd@gheryd-laptop:/etc/php5/apache2$ &lt;b&gt;ll&lt;/b&gt;
totale 76
drwxr-xr-x 2 root root  4096 2011-05-17 12:37 ./
drwxr-xr-x 5 root root  4096 2010-10-31 10:32 ../
lrwxrwxrwx 1 root root     9 2010-05-08 20:07 conf.d -&amp;gt; ../conf.d/
-rw-r--r-- 1 root root 67631 2011-05-17 12:37 &lt;b&gt;php.ini&lt;/b&gt;
&lt;/div&gt;&lt;/pre&gt;&lt;pre&gt;&lt;div style=&quot;background-color: black; color: white; padding: 10px;&quot;&gt;gheryd@gheryd-laptop:/etc/php5/apache2$ &lt;b&gt; sudo nano php.ini&lt;/b&gt;
&lt;/div&gt;&lt;/pre&gt;o se preferite l&#39;editor grafico&lt;br /&gt;
&lt;pre&gt;&lt;div style=&quot;background-color: black; color: white; padding: 10px;&quot;&gt;gheryd@gheryd-laptop:/etc/php5/apache2$ &lt;b&gt;sudo gedit php.ini &amp;amp;&lt;/b&gt;
&lt;/div&gt;&lt;/pre&gt;In evidenza le direttive con i valori da impostare.&lt;br /&gt;
&lt;pre&gt;&lt;div style=&quot;background-color: black; color: white; padding: 10px;&quot;&gt;; error_reporting = E_ALL &amp;amp; ~E_DEPRECATED
&lt;b style=&quot;color: yellow;&quot;&gt;error_reporting = E_ALL &amp;amp; ~E_NOTICE&lt;/b&gt;

; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It&#39;s recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
;   Off = Do not display any errors
;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
;   On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
&lt;b style=&quot;color: yellow;&quot;&gt;display_errors = On&lt;/b&gt;
&lt;/div&gt;&lt;/pre&gt;Ricordarsi di riavviare il server apache2:&lt;br /&gt;
&lt;pre&gt;&lt;div style=&quot;background-color: black; color: white; padding: 10px;&quot;&gt;gheryd@gheryd-laptop:/etc/php5/apache2$&lt;b&gt; sudo /etc/init.d/apache2 restart&lt;/b&gt;
&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/1468827038549619952/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/05/ubuntu-php-configurare-log-error.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1468827038549619952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/1468827038549619952'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/05/ubuntu-php-configurare-log-error.html' title='UBUNTU LINUX PHP configurare display log error'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1845163993653853397.post-4459828753042207489</id><published>2011-05-18T11:51:00.003+02:00</published><updated>2011-05-18T11:53:34.679+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="browser"/><category scheme="http://www.blogger.com/atom/ns#" term="firefox"/><title type='text'>browser firefox pagine  tab affiancate</title><content type='html'>Il mio collega ha trovato un utile plugin per affiancare le pagine web:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://addons.mozilla.org/it/firefox/addon/split-pannel/&quot;&gt;https://addons.mozilla.org/it/firefox/addon/split-pannel/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Utile per i developer ma anche non ;)</content><link rel='replies' type='application/atom+xml' href='http://gheryd.blogspot.com/feeds/4459828753042207489/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://gheryd.blogspot.com/2011/05/borwser-firefox-pagine-affiancate.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4459828753042207489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1845163993653853397/posts/default/4459828753042207489'/><link rel='alternate' type='text/html' href='http://gheryd.blogspot.com/2011/05/borwser-firefox-pagine-affiancate.html' title='browser firefox pagine  tab affiancate'/><author><name>gheryd</name><uri>http://www.blogger.com/profile/17314458170843113907</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNzuv13z17TBW02VRnKV2-frTfkI9kSeWQUNzu-TASi1Fhly1Z5ud5qn7XpVjNZ0kV9YY0TTcWb53aFn0dJ0W4HTYxpgF6GLK6Z-QOJjgfen_4aalS3DBqNoqCLZDAYw/s220/castorone.jpg'/></author><thr:total>0</thr:total></entry></feed>