ÉîÈëÀí½âJavaScript±Õ°ü
±¾ÎÄת×Ô£ºhttp://www.felixwoo.com/archives/247
×î½üÔÚÍøÉϲéÔÄÁ˲»ÉÙJavascript±Õ°ü(closure)Ïà¹ØµÄ×ÊÁÏ£¬Ð´µÄ´ó¶àÊǷdz£µÄѧÊõºÍרҵ¡£¶ÔÓÚ³õѧÕßÀ´Ëµ±ð˵Àí½â±Õ°üÁË£¬¾ÍÁ¬ÎÄ×ÖÐðÊö¶¼ºÜÄÑ¿´¶®¡£×«Ð´´ËÎĵÄÄ¿µÄ¾ÍÊÇÓÃ×îͨË×µÄÎÄ×Ö½Ò¿ªJavascript±Õ°üµÄÕæʵÃæÄ¿¡£
Ò»¡¢Ê²Ã´ÊDZհü£¿
“¹Ù·½”µÄ½âÊÍÊÇ£º±Õ°üÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
ÏàÐźÜÉÙÓÐÈËÄÜÖ±½Ó¿´¶®Õâ¾ä»°£¬ÒòΪËûÃèÊöµÄ̫ѧÊõ¡£ÆäʵÕâ¾ä»°Í¨Ë×µÄÀ´Ëµ¾ÍÊÇ£ºJavaScriptÖÐËùÓеÄfunction¶¼ÊÇÒ»¸ö±Õ°ü¡£²»¹ýÒ»°ãÀ´Ëµ£¬Ç¶Ì×µÄfunctionËù²úÉúµÄ±Õ°ü¸üΪǿ´ó£¬Ò²ÊǴ󲿷ÖʱºòÎÒÃÇËùνµÄ“±Õ°ü”¡£¿´ÏÂÃæÕâ¶Î´úÂ룺
function a() {
var i = 0;
function b() {
alert(++i);
}
return b;
}
var c = a();
c();
Õâ¶Î´úÂëÓÐÁ½¸öÌص㣺
º¯ÊýbǶÌ×ÔÚº¯ÊýaÄÚ²¿£»
º¯Êýa·µ»Øº¯Êýb¡£
ÒýÓùØϵÈçͼ£º
ÕâÑùÔÚÖ´ÐÐÍêvar c=a()ºó£¬±äÁ¿cʵ¼ÊÉÏÊÇÖ¸ÏòÁ˺¯Êýb£¬bÖÐÓõ½Á˱äÁ¿i£¬ÔÙÖ´ÐÐc()ºó¾Í»áµ¯³öÒ»¸ö´°¿ÚÏÔʾiµÄÖµ(µÚÒ»´ÎΪ1)¡£Õâ¶Î´úÂëÆäʵ¾Í´´½¨ÁËÒ»¸ö±Õ°ü£¬ÎªÊ²Ã´£¿ÒòΪº¯ÊýaÍâµÄ±äÁ¿cÒýÓÃÁ˺¯ÊýaÄڵĺ¯Êýb£¬¾ÍÊÇ˵£º
µ±º¯ÊýaµÄÄÚ²¿º¯Êýb±»º¯ÊýaÍâµÄÒ»¸ö±äÁ¿ÒýÓõÄʱºò£¬¾Í´´½¨ÁËÒ»¸öÎÒÃÇͨ³£ËùνµÄ“±Õ°ü”¡£
ÈÃÎÒÃÇ˵µÄ¸ü͸³¹Ò»Ð©¡£Ëùν“±Õ°ü”£¬¾ÍÊÇÔÚ¹¹Ô캯ÊýÌåÄÚ¶¨ÒåÁíÍâµÄº¯Êý×÷ΪĿ±ê¶ÔÏóµÄ·½·¨º¯Êý£¬¶øÕâ¸ö¶ÔÏóµÄ·½·¨º¯Êý·´¹ýÀ´ÒýÓÃÍâ²ãÍâ²ãº¯ÊýÌåÖеÄÁÙʱ±äÁ¿¡£ÕâʹµÃֻҪĿ±ê ¶ÔÏóÔÚÉú´æÆÚÄÚʼÖÕÄܱ£³ÖÆä·½·¨£¬¾ÍÄܼä½Ó±£³ÖÔ¹¹Ô캯ÊýÌ嵱ʱÓõ½µÄÁÙʱ±äÁ¿Öµ¡£¾¡¹Ü×ʼµÄ¹¹Ô캯Êýµ÷ÓÃÒѾ½áÊø£¬ÁÙʱ±äÁ¿µÄÃû³ÆÒ²¶¼ÏûʧÁË£¬µ«ÔÚÄ¿ ±ê¶ÔÏóµÄ·½·¨ÄÚȴʼÖÕÄÜÒýÓõ½¸Ã±äÁ¿µÄÖµ£¬¶øÇÒ¸ÃÖµÖ»ÄÜͨÕâÖÖ·½·¨À´·ÃÎÊ¡£¼´Ê¹Ôٴε÷ÓÃÏàͬµÄ¹¹Ô캯Êý£¬µ«Ö»»áÉú³ÉжÔÏóºÍ·½·¨£¬ÐµÄÁÙʱ±äÁ¿Ö»ÊǶÔӦРµÄÖµ£¬ºÍÉÏ´ÎÄǴε÷ÓõÄÊǸ÷×Ô¶ÀÁ¢µÄ¡£
ΪÁ˸üÉî¿ÌµÄÀí½â±Õ°ü£¬ÏÂÃæÈÃÎÒÃǼÌÐø̽Ë÷±Õ°üµÄ×÷ÓúÍЧ¹û¡£
¶þ¡¢±Õ°üÓÐʲô×÷ÓúÍЧ¹û£¿
¼ò¶øÑÔÖ®£¬±Õ°üµÄ×÷ÓþÍÊÇÔÚaÖ´ÐÐÍê²¢·µ»Øºó£¬±Õ°üʹµÃJavascriptµÄÀ¬»ø»ØÊÕ»úÖÆGC²»»áÊÕ»ØaËùÕ¼ÓõÄ×ÊÔ´£¬ÒòΪaµÄÄÚ²¿º¯ÊýbµÄÖ´ÐÐÐèÒªÒÀÀµaÖеıäÁ¿¡£ÕâÊǶԱհü×÷Óõķdz£Ö±°×µÄÃèÊö£¬²»×¨ÒµÒ²²»ÑϽ÷£¬µ«´ó¸ÅÒâ˼¾ÍÊÇÕâÑù£¬Àí½â±Õ°üÐèÒªÑÐò½¥½øµÄ¹ý³Ì¡£
ÔÚÉÏÃæ
Ïà¹ØÎĵµ£º
.XML Web services ÐÐΪʹ¿Í»§¶Ë½Å±¾Äܹ»µ÷ÓÃÓÉ Microsoft .NET XML Web services »òÆäËûÖ§³Ö¼òµ¥¶ÔÏó·ÃÎÊÐÒé (SOAP) µÄ Web ·þÎñÆ÷¹«¿ªµÄÔ¶³Ì·½·¨¡£
Ä¿µÄ£ºÌṩһÖÖ¼òµ¥µÄ·½·¨Ê¹ÓúÍÀûÓà SOAP£¬¶ø²»Ðè¾ßÓÐ SOAP ʵÏÖµÄרҵ֪ʶ¡£
²½Ö裺
1.ÏÂÔØWebservice.htc,Ðí¶àÍøÉϵÄÎÄÕ½éÉܸÃÎļþ¿ÉÒÔÔÚ΢ÈíµÄÍøÕ¾ÉÏÕÒµ½£¬µ«ÎÒ°´ ......
×î½üµÄÏîÄ¿¿ª·¢ÖÐ Óöµ½Ò»Ð©ÐèÒª¸ù¾Ý¾ßÌåÇé¿ö¶¯Ì¬Ìí¼ÓjavaScript½Å±¾£¬È»ºóÖ´Ðнű¾ ÓÚÊÇÊÕ¼¯ÁËһϣº
1 ÔڿؼþµÄ°ó¶¨Ê¼þÖÐÌí¼Ó½Å±¾ È磺ÔÚgridview¿Ø¼þµÄrowdatabindʼþÖпÉÒÔʵÏÖ Ö¸ÕëµÄÑ¡ÖÐÐв»Í¬É«ÏÔʾ ¿ÉÌí¼Ó½Å±¾
protected void gvEngineerRepairState_RowDataBound(object sender, GridViewRowEventArgs e ......
ÖÐÎıàÂ룺
function upload() {
var form = document.getElementById('topic');
if ($('uploadfile').value == "") {
alert("ÇëÑ¡ÔñÎļþ£¡");
return;
}
$('uploadfile').value = escape($('uploadfile').value) ......
1.delete ÔËËã·û
¶ÔÏóɾ³ýÒ»¸öÊôÐÔ£¬»òÊý×éÖÐɾ³ýÒ»¸öÔªËØ¡£½«ÎÞÓõÄÄÚÈÝɾ³ýÒÔ½ÚÊ¡¿Õ¼ä¡£
delete expression
example:
var person = new Object();
person.sex = "male";
alert(person.sex);
delete person.sex;
alert(person.sex);
2. ‘,' ÔËËã·û
var a = 2;
......
Javascriptº¯ÊýÀàÐÍÅжÏÍêÃÀ½â¾ö·½°¸
ÔÚÅжϺ¯ÊýÀàÐÍʱ£¬ÎÒÃÇͨ³£Ê¹ÓÃtypeof·½·¨£¬Ò»°ãÇé¿öÏ£¬Ëü»áµÃµ½ÎÒÃÇËùÔ¤ÏëµÄЧ¹û¡£µ«ÊÇ£¬ÓÐһЩϸ½Ú²¢²»ÎªÎÒÃÇËùÊìÖª¡£John Resig ÔÚ·ÖÎöÁËÕâЩϸ½ÚÖ®ºó£¬ÎªÎÒÃÇÌṩÁËÒ»¸öÍêÃÀµÄ½â¾ö·½°¸£¬±¾ÎĽ«×÷Ïêϸ½éÉÜ£º
Ò»¡¢´«Í³·½·¨²»ÎªÈËËùÖªµÄϸ½Ú
ºÁÎÞÒÉÎÊ£¬ÔÚÅжϺ¯ÊýÀàÐÍʱ£¬ÎÒÃÇÊ ......