w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS Guidelines
Some other important things to know when scripting with JavaScript.
ʹÓÃJSʱ»¹Ó¦¸ÃÁ˽âµÄÒ»Ð©ÖØÒªÐÅÏ¢¡£
A function named "myfunction" is not the same as "myFunction" and a variable named "myVar" is not the same as "myvar".
º¯ÊýÃû³ÆÎª"myfunction"²¢²»ºÍ"myFunction"Ïàͬ£¬Í¬ÑùÒ»¸ö½Ð×ö"myVar"µÄ±äÁ¿ºÍ½Ð×ö"myvar"µÄÒ²²»Ò»Ñù¡£
JavaScript is case sensitive - therefore watch your capitalization closely when you create or call variables, objects and functions.
¾ÍÒòΪJSÇø·Ö´óСд-ËùÒÔµ±Ä㽨Á¢»òµ÷ÓñäÁ¿£¬¶ÔÏóºÍº¯ÊýµÄʱºò×Ðϸ¿´¿´ÄãµÄ´óд¡£
JavaScript ignores extra spaces. You can add white space to your script to make it more readable. The following lines are equivalent:
JS»áºöÂÔ¶àÓàµÄ¿Õ°×¡£Äã¿ÉÒÔÔÚÄãµÄ½Å±¾Àï¼ÓһЩ¿Õ°×À´Ôö¼Ó¿É¶ÁÐÔ¡£ÏÂÃæÁ½ÐÐЧ¹ûÊÇÒ»ÑùµÄ£º
name="Hege" |
You can break up a code line within a text string with a backslash. The example below will be displayed properly:
Äã¿ÉÒÔÔÚÎÄ×Ö´®ÖмÓÈ뷴б¸ÜÀ´½«Ò»¶Î´úÂë²ð¿ª¡£ÏÂÃæµÄÀý×Ó½«Õý³£ÏÔʾ£º
document.write("Hello \
|
However, you cannot break up a code line like this:
È»¶øÄã¾Í²»ÄÜÕâÑùÀ´²ð·Ö
document.write \ |
You can add comments to your script by using two slashes //:
Äã¿ÉÒÔʹÓÃ˫б¸ÜÀ´Ìí¼ÓÄã½Å±¾µÄ×¢ÊÍ£º
//this is a comment |
or by using /* and */ (this creates a multi-line comment block):
»òÕßʹÓÃ/*ºÍ*/£¨Õâ¸ö¿ÉÒÔ½¨Á¢¶àÐеÄ×¢ÊÍÇø£©£º
/* This is a comment |