���Ѥ�Í�Ѥʹͻ���������Ľ��פʻ�Ŧϳ�줬���롣
ITï¿½ïµ - JavaScript ��ؤֺݤ˰��ֽ��פʤΤˡ����ò¤µ¤ì¤¬ï¿½ï¿½ï¿½ï¿½ setTimeout �Ϥγ�ǰsetInterval��setTimeout�����٥�Ȥˤ��ؿ��μ¹Ԥ����ò¤¹¤ë¤³ï¿½È¤ï¿½ï¿½È»×¤ï¿½
�ڡ��������ĺ����褵��뤫���Ȥ������ȤǤ��롣
̤�и��Ԥϡ�document.write()��element.innerHTML = "foo"�Τ褦�ˡ��֥饦�����ˡֽñ¤½Ð¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ç¤ï¿½ï¿½ì¤¬Ä¾ï¿½ï¿½ï¿½ï¿½È¿ï¿½Ç¤ï¿½ï¿½ï¿½ï¿½È»×¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½
�Ȥ������������ǤϤʤ��ΤǤ��롣
����򸫤Ƥߤ褦���ʲ���script��ͤ��Ƥߤ롣�ܥ���򲡤��ȡ��ܥ���Υ�٥뤬1000����1�ޤǥ�����ȥ����󤷤��塢���̤�ˤʤ뤳�Ȥ�տޤ��Ƥ���褦�˸����롣
<script> function bad_count(evt){ var self = evt.target || evt.srcElement; for (var count = 1000; count > 0; count--){ self.value = count; } self.value="count"; } </script> <input type="submit" value="count" onclick="bad_count(event)">
�Ȥ����������Υܥ���ϴ����̤�ư���ʤ�������å����Ƥⲿ�ⵯ���ʤ��褦�ˤ��������ʤ���
����Ϥʤ���?��������̩�����롣
�ؿ��μ¹���ϡ��ڡ����νñ¤´ï¿½ï¿½ï¿½ï¿½Ïµï¿½ï¿½ï¿½ï¿½ï¿½Ê¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ê¤ï¿½ï¿½ï¿½ï¿½ï¿½Ø¿ï¿½ï¿½Î¼Â¹Ô¥ï¿½ï¿½å¡¼ï¿½ï¿½ï¿½ï¿½ï¿½Ë¤Ê¤Ã¤Æ»ï¿½ï¿½ï¿½ï¿½Ç¤Ï¤ï¿½ï¿½ï¿½Æ¥Ú¡ï¿½ï¿½ï¿½ï¿½Î½ñ¤´ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Î¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½åµï¿½ï¿½ï¿½ï¿½Ç¤Ï¡ï¿½ï¿½Ç½ï¿½ï¿½Â¹Ô·ï¿½Ì¤Î¤ß¤ï¿½É½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½È¤ï¿½ï¿½ï¿½ï¿½ï¤±ï¿½ï¿½ï¿½ï¿½
���ߤΥ֥饦�����μ����ϡ��ʲ��Τ褦�ˤʤäƤ���褦�Ǥ��롣�֤褦�Ǥ���פȤ����Τϡ����ͽ�dz�ǧ�����櫓�ǤϤʤ��������
���٥��ȯ�� �� �ؿ��μ¹� �� �ڡ����κ�����
�åµï¿½ï¿½ï¿½ï¿½Ç°Õ¿Þ¤ï¿½ï¿½ï¿½ï¿½è¤¦ï¿½Ë¡ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ó¥¿¡ï¿½ï¿½ï¿½Æ°ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½É½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½È»×¤Ã¤ï¿½ï¿½é¡¢ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ù´Ø¿ï¿½ï¿½Î¼Â¹Ô¤ï¿½Î»ï¿½ï¿½ï¿½Ê¤ï¿½ï¿½ï¿½Ð¤Ê¤ï¿½Ê¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ó¥¿¡ï¿½ï¿½ï¿½Æ°ï¿½ï¿½ï¿½ï¿½ï¿½È¤ï¿½ï¿½ï¿½ï¿½Ô°Ù¤ï¿½ï¿½Î¤ï¿½Î¤Ë´Ø¿ï¿½ï¿½Î¼Â¹Ô¤ï¿½É¬ï¿½×¤Ç¤ï¿½ï¿½ë¡£ï¿½É¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½è¤¤ï¿½ï¿½?
������������setTimeout()�Ȥ����櫓�����åµï¿½ï¿½ï¿½ï¿½Ç¤Ï¡ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ó¥¿¡ï¿½ï¿½ï¿½ï¿½ï¿½Æ°ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½é¡¢ï¿½ï¿½ï¿½Ë¥ï¿½ï¿½ï¿½ï¿½ó¥¿¡ï¿½ï¿½ï¿½Æ°ï¿½ï¿½ï¿½ï¿½ï¿½Ø¿ï¿½ï¿½ï¿½setTimeout()����Ͽ���롣����Ȼ�������ʾ���ˤ��δؿ���¹Ԥ���Ȥ������٥�Ȥ�ȯ�������ޤ����δؿ����¹Ԥ��졢�ڡ����������褵��롣
�����ºݤˤ��Ȥɤ��ʤ뤫?�ʲ��Τ褦�ˤʤ롣
<script> var count; var timer; function good_count(evt){ var self = evt.target || evt.srcElement; count = 1000; var callback = function(){ self.value = count--; if (count > 0){ timer = setTimeout(callback, 0); }else{ self.value = "count"; } } timer = setTimeout(callback, 0); } </script> <input type="submit" value="count" onclick="good_count(event)">
���٤Ϥ�����ư����������ư���������Τ�䤳�����ϰ��β�����������������������Хå��ؿ���Ȥä����٥�Ƚ����Ȥ����Τϡ�GUI�ץ�����ߥ󥰤�и������ͤǤ���Ф������ٴ������Ĥ����Ȼפ������༡Ū�˽��������ץ�����ष���񤤤����Ȥ��ʤ��ͤˤϡ֥ϥ�?�פ�������������
���������Τ������ǡ��ץ�������ּ¹���פ����Ǥ��뤳�Ȥ��ǽ�ˤʤ롣�ʲ��ϥ����󥿡���ư���Ƥ���֤˥ܥ���򥯥�å�����ȥ�����Ȥ����Ǥ��������
function better_count(evt){ var self = evt.target || evt.srcElement; if (timer){ timer = clearTimeout(timer); // clearTimeout(timer); timer = undefined; return; } if (! count) count = 1000; var callback = function(){ self.value = count--; if (count > 0){ timer = setTimeout(callback, 10); }else{ timer = clearTimeout(timer); self.value = "count"; } } timer = setTimeout(callback, 10); }
�ȤϤ��������Τ�����϶ˤ����ľ��Ū�ǡ��Х��β����Ȥ�ʤꤦ�롣�ä˥�����Хå��ؿ���ñ¤¯»ï¿½ï¿½Ë¤Ï¡ï¿½ï¿½Ö½ï¿½Î»ï¿½×½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½È¤ï¿½ï¿½Ê¤ï¿½ï¿½È¼ï¿½ò·¹¤ï¿½ï¿½ï¿½Ð¥ï¿½ï¿½ï¿½È¯ï¿½ï¿½ï¿½ï¿½ï¿½È¤Ê¤ë¡£ï¿½ï¿½ï¿½ï¿½ï¿½Î¸ï¿½ï¿½clearTimeout()��ñ¤²Ã¤ï¿½ï¿½Æ¤ï¿½ï¿½ï¿½ï¿½Ê¤ï¿½ï¿½È¡ï¿½ï¿½Ö¼Â¹Ô½ï¿½Î»ï¿½×¸ï¿½ï¿½ï¿½ï¿½ï¿½Ù¥ï¿½ï¿½ï¿½Ã¥ï¿½ï¿½ï¿½ï¿½Ê¤ï¿½ï¿½ÈºÆ¥ï¿½ï¿½ï¿½ï¿½ï¿½È¤ï¿½ï¿½Ê¤ï¿½ï¿½ï¿½ï¿½Ü¤Ë¤Ê¤ë¡£
�ºݡ�Javascript�ˤ����뤳�����������Ȥ����Τϡ���Ϥ�preemptive multitasking�ʴĶ�����Ӥ������ľ�ñ¤¤Å¤é¤¤ï¿½È»×¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Unix��sleep()���٤Τ��ȤǤ��ηä�ʤ�ʤ��ƤϤʤ�ʤ������ä���Ȥ��Ƥΰ��ݤǤϡ�OS X�ˤʤ�����System 7�ʹߤ�Mac OS�δ��Ф˻��Ƥ��롣�����Ϥ����cooporative multitasking�ȸƤ�Ǥ��ä��������ǽ�����OS���֤��ʤ��ȡ����ĤޤǤ��äƤ�Ĥ�Υץ��������Ԥ�����뱩�ܤˤʤ����ˤ����ơ����ߤΥ֥饦�����ˤ��ä���ʤΤ���
�֥饦������OS�ˤʤ뤴�����Ǥ��롣������preemptive�ˤʤä��ߤ����Ȼפ��Τϻ�����������������ʤ��Ȥ⡢Unix��fflush()Ū�ʤ�Τ��ߤ������ؿ�����Ǥ⤽���Ƥ֤ȶ���Ū�˥ڡ��������褵���褦�ʴؿ�����window.refresh()���Ȥ���
Dan the Javascripter
���Υ֥����˥����Ȥ���ˤ�����������ɬ�פǤ���
��������������
���ε����ˤϵ��ĥ桼�����������Ȥ��Ǥ��ޤ���