JavaScriptªºµ{¦¡¬yµ{»P°ò¥»»Pªk |
JavaScriptªº«ü¥O¡]Statement¡^©MC/C++ªø±oÆZ¹³ªº¡A¬O¥Ñ¬Y¨ÇÃöÁä¦r¡]KEyword¡^¤Î¦X
ªkªº»yªk©Ò²Õ¦¨¡F§@¥Î¶È¬O§i¶D¹q¸£¸Ó°µ¤°»ò¡I§Ú̦b¼¶¼g«ü¥O®É¥i¥H±N³æ¤@«ü¥O³v
¦æ¼¶¼g;¦h««ü¥O¤]¥i¬°¦b¦P¤@¦æ¡C
¤£¹L¨C¹D«ü¥O¶¡¥²¶·¥H¤À¸¹¡]¡F¡^¬Û¹j¡C©Ò¥H¶}©l¼¶¼gJavaScript¤]±o±q¤@¨Ç°ò¥»«ü¥O
¤Î»yªk¾Ç°_¡C
µù¸Ñ¡]Comment¡^«ü¥Oªº¥Øªº¬O¥Î¨Ó¼W¥[µ{¦¡¤º®eªº¥iŪ©Ê¡A¼W¥[µ{¦¡ºûÅ@¤Î°£¿ùªº
¤è«K©Ê¡F¦b JavaScript¤¤µù¸Ñ«ü¥O¬O¤£¥i¥H°õ¦æªº¡A¨Ï¥Î
¤èªk¦³¨âºØ¡G
1.//³æ¤@«ü¥O
2.//*¬Y°Ï¶ô¤ºªº ¦h««ü¥O*/
þ While«ü¥O©MC/C++¤¤ªºWhile¤@¼Ë,¥i°õ¦æ¤@өΦhÓJavaScript«ü¥O¡C
While«ü¥O«á±µ¤@Ó±ø¥ó§PÂ_¦¡¡A¦pªGµ²ªG¬°
true¡A«hµ{¦¡°õ¦æ¤º
§tªº¹Bºâ¦¡¡Cn¬O§PÂ_¦¡¬°
false¡A«h¸õ¥X°j°é¡C¨Ò¦p¥H¤Uµ{¦¡¤ùÂ_¡G
var i=10
while (i>0)
{
i--
document.write(i+"<br>")
} |
for«ü¥O¤]¦p¦P C/C++¤¤¤@¯ë¡A¥i»s³y¤@Ó¥i°õ¦æ°j°é¡]loop¡^;©Mwhile«ü¥OÃþ¦ü¡C
¤£¹L«ü¥O§Î¦¡´N§¹¥þ¤£¦P¤F¡Afor«ü¥O¥]§t¤F¤TÓ¿ï
¾Ü©Ê°Ñ¼Æ¡C®æ¦¡¦p¤U¡G
for¡]ªìȪº³]©w;±ø¥ó§PÂ_¦¡;§ó·s±Ôz¡^
{
³æ¤@«ü¥O©Î¦h««ü¥O°Ï¶ô
}
¹ï©ó¡uªìȪº³]©w¡v¡]initial¡^³¡¥÷³q±`¬O³]©w¤@Ó¥ip¼ÆªºÅܼƨõ¹
¤©ªìÈ¡A¦Ó±ø¥ó§PÂ_¦¡¡]
conditional¡^«h¥Î¨ÓÀˬd¨C¤@¦¸°j°éªº°õ¦æ¡C
¦pªG§PÂ_¦¡¬° true«h°õ¦æ¬A¸¹¤ºªº«ü¥O¡C¤Ï¤§¡A«h¸õÂ÷°j°é¡C§ó·s±Ôz
¡] update expression ) ¬O¥Î¨Ó§ó·s¨C¦¸°õ¦æ°j°é«áp¼ÆÅܼƪºÈ¡C½Ðª`
·N!³o¤TºØ°Ñ¼Æ¥i³£¬O¿ï¾Ü©Ê¡]
Optional¡^ªº³á!¥H¤U¬O for«ü¥Oªºµ{¦¡
¬q½d¨Ò¡G
1
. var sum=0
for(var i=10; i>0; i--)
{
sum+=i
document.write(sum+"<br>")
} |
2.
var i=5
for(;i>0;)
{
document.write(i+"."+"<br>")
} |
³o©M¤@¯ë»y¨¥¤¤ªº
If...else«ü¥O¤@¼Ë¡A¤]´N¬O¦pªGº¡¨¬±ø¥ó§PÂ_¦¡©Ò³]
©wªº±ø¥ó¡A«hif«áªº¹Bºâ¦¡±N³Q°õ¦æ¡C§_«h´N°õ¦æelse¤§«áªº¹Bºâ¦¡¡C
®æ¦¡¦³¨âºØ¡G
1.
If(±ø¥ó§PÂ_¦¡)
{
¦h««ü¥O°Ï¶ô1
}
else
{
¦h««ü¥O°Ï¶ô2
}
2.
If(±ø¥ó§PÂ_¦¡)
³æ¤@«ü¥O1
else
³æ¤@«ü¥O2
¥H¤U¬OIf«ü¥Oªºµ{¦¡¤ùÂ_:
if(string1="yes")
document.write('³o¦r¦êªº¤º®e¬O"yes")
else
document.write('³o¦r¦êªº¤º®e¬O"no")
withªº¥Dn¥\¯à¬O¥Î¨Ó³B²z²¤Æª«¥ó(object)ªº¬ÛÃö¨Æ¶µ
¡C
withªº¨Ï¥Î®æ¦¡¦p¤U:
with( ª«¥ó¦WºÙ )
( ps.ª«¥ó¨â®Ç¤@©wn¦³¬A¸¹)
{
«ü¥O°Ï¶ô
}
* JavaScriptªº¨ç¼Æ(function)¤¶²Ð
* |
¨ç¼Æ¡] function¡^¦b JavaScript¤¤©Ò¦ûªº¥÷¶q¯u¬O«D¦P¤p¥i¡A¤£¦ý
¥i°µ ¬°µ²ºc¤Æµ{¦¡¡]
Structured Programming¡^¤¤¨ç¼Æªº§@¥Î;¬Æ¦Ü©ó
JavaScript¤¤ªºª«¥ó¡]
Object¡^³£¥²¶·É¥Î¨ç¼Æªºµ²ºc¡C·íµM¡A¨ç¼Æªº
¥Dn¥\¯àÁÙ¬O°µ¬°¥Dµ{¦¡¬[ºc¤§¥~ªº°Æµ{¦¡¤§¥Î¡CJavaScript¤¤ªº¨ç¼Æ
¬O§Q¥ÎÃöÁä¦r¡]keyword¡^
function«Å§i¨ç¼Æ¦WºÙ¤Î«á©Ò±µ°Ñ¼Æ
¡] Parameter¡^¡A¦Ó°Ñ¼Æ©Ò¶Ç»¼ªº¤Þ¼Æ¡]argument¡^¥i¥H¬O¼ÆÈ¡B¦r¦ê
¤Îª«¥óµ¥¡C¥ý¨Ó¬Ý¤@Ó¹ê»Ú¥Ñ
JavaScript¼g¦¨ªº¤p¨ç¼Æ¡G
function add(x,y)
{
var sum
sum=x+y
return sum
} |
¯Âºé´N¨ç¼Æªº¥\¯à¦Ó¨¥¡A¤£¦Ò¼{¦b
JavaScript¤¤ª«¥óªºµ²ºc¡F¨º§ÚÌ¥i
¥HªÖ©w JavasScript¤¤ªº¨ç¼Æ©M¨ä¥L»y¨¥¤¤ªº¨ç¼Æ¤]¬O¤j¦P¤p²§¡C¤£¹Lµ§
ªÌÁÙ¬O±N JavaScript¤¤ªº¨ç¼Æ¯S©Ê¡]
Property¡^¾ã²z¦p¤U¡G
1.¨ç¼Æ¤¤°Ñ¼Æªº¶Ç»¼³£¬O§Q¥Î¶ÇȪk¡]
Call by value¡^,¶ÇȪk¦³¤T¶µ
¯SÂI¡G
1.±N¥Dµ{¦¡ªº¤Þ¼ÆÈ,¶Ç°eµ¹¨ç¼Æªº°Ñ¦Ò¡C |
2.µL½×¨ç¼ÆªºÈ¦p¦ó§ïÅÜ,¨Ã¤£·|¼vÅT¥Dµ{¦¡ªº¤Þ¼ÆÈ¡C |
3.¨ç¼Æ¥²¶·ªá¶O©M¥Dµ{¦¡ªº¤Þ¼Æ¤£¦PªºÃB¥~°O¾ÐªÅ¶¡¨Ó
Àx¦s,¦Ó¥B ¨ç¼Æ°õ¦æ§¹²¦«á,§Y§âÃB¥~ªÅ¶¡ÁÙµ¹CPU¡C |
¤]´N¬O Javascript¤¤¨ç¼ÆªºÅܤƤ£·|¼vÅT¨ì¥Dµ{¦¡¡F¦b¨ç¼Æ¤¤©Ò«Å§iªº
¨ç¼Æ¡A§Ú̺٬°°Ï°ìÅܼơ]
local variable¡^¡C¨ç¼Æ¥~©Ò«Å§iªºÅܼƧÚÌ
´NºÙ¬°¥þ°ìÅܼơ]glohal
Variable¡^¡Cn´£¿ô±zª`·Nªº¬O¦b¨ç¼Æ¤º¦pªG
°Ï°ìÅܼƻP¥þ°ìÅܼƬۦP¦WºÙ¡]the
same name¡^¡A«h°Ï°ìÅܼƪºÀu¥ý
Åv¡] precedence¡^°ª©ó¥þ°ìÅܼơC
2. ¨ç¼Æn¶ÇȦ^¥h¥i¥ÎÃöÁä¦r
return¡C¦ý¦³¨Ç¨ç¼Æ¤£¶ÇÈ¡A¬G¨S¦³
return¤]¥i¥H¡C¦ÛµM¦³¨Ç¨ç¼Æ¨S¦³¥ô¦ó°Ñ¼Æ¤]¦æ±o³q³á!
回到前頁