HighDots Forums  

solo un parere.

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss solo un parere. in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
abramo
 
Posts: n/a

Default solo un parere. - 05-26-2008 , 06:21 AM






window.onload=function() {
var field=document.getElementsByTagName('form')[0].elements;
document.getElementById('cambioPassword').onsubmit =function() {
if(validateForm()){startRequest();}
return false;
}

questo codice puo' andare bene oppure si puo' fare di meglio e con piu'
eleganza?

Reply With Quote
  #2  
Old   
eliu
 
Posts: n/a

Default Re: solo un parere. - 05-26-2008 , 07:31 AM






abramo wrote:
Quote:
window.onload=function() {
var field=document.getElementsByTagName('form')[0].elements;
document.getElementById('cambioPassword').onsubmit =function() {
if(validateForm()){startRequest();}
return false;
}

questo codice puo' andare bene oppure si puo' fare di meglio e con piu'
eleganza?
Ci si può affidare ad un framework Javascript come Jquery, Mootools o
Prototype per scrivere codice elegante e superare le differenze fra browser.

--
Giovanni Cappellini - http://quacos.wordpress.com

Realizzazione siti dinamici e consulenze OpenSource:
http://www.weblogix.biz


Reply With Quote
  #3  
Old   
ZER0
 
Posts: n/a

Default Re: solo un parere. - 05-26-2008 , 07:47 AM



On 26 May 2008 11:21:44 GMT, abramo wrote:

Quote:
window.onload=function() {
var field=document.getElementsByTagName('form')[0].elements;
field la dichiari come locale, ma non c'è alcun uso localmente di tale
variabile. Inoltre potresti eliminare getElementsByTagName:

var field = document.forms[0].elements;

Quote:
document.getElementById('cambioPassword').onsubmit =function() {
if(validateForm()){startRequest();}
return false;
}
Se "startRequest()" fa tutto il lavoro, come sembra, potresti andare a
integrare validateForm() all'interno della funzione. In questo modo si
va a eliminare una closure superflua:

document.getElementById("cambioPassword").onsubmit = startRequest;

Quote:
questo codice puo' andare bene oppure si puo' fare di meglio e con piu'
eleganza?
Puoi raggiungere una maggiore eleganza se cambi approccio. Ma questo è
più inerente alla metodologia piuttosto che al codice in sé.
Ad esempio, utilizzando qualche Design Pattern; incapsulando il codice
in oggetti.

--
~ Ci si aspetta di tutto, ma non si e' mai preparati a nulla.
(M.Swetchine)



Reply With Quote
  #4  
Old   
abramo
 
Posts: n/a

Default Re: solo un parere. - 05-26-2008 , 08:40 AM



Quote:
Puoi raggiungere una maggiore eleganza se cambi approccio. Ma questo è
più inerente alla metodologia piuttosto che al codice in sé. Ad esempio,
utilizzando qualche Design Pattern; incapsulando il codice in oggetti.
Tipo design pattern?


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.