Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Javascript±Õ°ü(Closure)

ClosureÖÐÎÄ·­ÒëΪ±Õ°ü.×ÖÃæÉÏÀ´Àí½â¾ÍÊÇ"·â±ÕµÄ°ü".(ÕâÊÇÒ»¾ä·Ï»°)
±Õ°üÊÇʲô?
ÊéÃæ½âÊÍΪ: Ëùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
ÎÒÈÏΪ±Õ°ü¾ÍÊÇÄܹ»¶Á/дº¯ÊýÄÚ²¿µÄijЩ±äÁ¿µÄ×Óº¯Êý,²¢½«ÕâЩ±äÁ¿±£´æÔÚÄÚ´æÖÐ.
±Õ°üµÄ×÷ÓÃ
ÉÏÃæµÄ¸ÅÄîÖÐÒѾ­Ìáµ½¹ý,Ö÷Òª¾ÍÊÇΪÁ˶Á/дº¯ÊýÄÚ²¿µÄijЩ±äÁ¿,²¢½«Ëü±£³ÖÔÚÄÚ´æÖÐ.¿ÉÄÜÕâÑù½²Î´±ØÕâôÈÝÒ×Àí½â,ÏÂÃæÈÃÎÒÃÇÀ´¿´Ò»Ð©Àý×Ó:
1,¶ÁÈ¡¾¯²ìµÄÉúÃüÖµ
function PoliceMan() {
//¶¨Òå³õʼÉúÃüÖµ
var lifeEnergy = 100;
//ÏÔʾµ±Ç°ÉúÃüÖµ
function showLifeEnergy() {
alert(lifeEnergy);
}
return showLifeEnergy;
}
//´´½¨Ò»¸ö¾¯²ì
var pm = new PoliceMan();
//ÏÔʾµ±Ç°ÉúÃüÖµ
pm();
2,¶Áд/±£´æ ¾¯²ìµÄÉúÃüÖµ
function PoliceMan() {
//¶¨Òå³õʼÉúÃüÖµ
var lifeEnergy = 100;
//Öе¯¼õÉÙÉúÃüÖµ
InBullet = function(){
lifeEnergy -= 1;
}
//ÏÔʾµ±Ç°ÉúÃüÖµ
function showLifeEnergy() {
alert(lifeEnergy);
}
return showLifeEnergy;
}
//´´½¨Ò»¸ö¾¯²ì
var pm = new PoliceMan();
//ÏÔʾµ±Ç°ÉúÃüÖµ
pm();
//Öе¯¼õÉÙÉúÃüÖµ
InBullet();
//ÏÔʾµ±Ç°ÉúÃüÖµ
pm();
×¢ÒâÊÂÏî
ÓÉÒÔÉÏÀý×ÓÎÒÃÇ¿ÉÒÔ¿´µ½¾¯²ìµÄÉúÃüÖµ±äÁ¿lifeEnergy»áһֱפÁôÔÚÄÚ´æµ±ÖÐ.Èç¹ûÕâÖÖ·½·¨Ê¹ÓÃƵ·±,ÄÇôºÜÈÝÒ׾ͰѻúÆ÷µÄÄÚ´æÏûºÄÍê.Òò´Ë½¨ÒéÄÜÓú¯ÊýµÄµØ·½¾Í¾¡Á¿Ê¹Óú¯Êý,¶ø²»ÒªÊ¹Óñհü.
×÷Õߣº·ÊÕ¼
³ö´¦£ºhttp://extjs.org.cn
±¾ÎÄ°æȨ¹é×÷ÕߺÍExtJsÖÐÎÄ×ÊѶվ¹²ÓУ¬»¶Ó­×ªÔØ£¬µ«Î´¾­×÷ÕßͬÒâ±ØÐë±£Áô´Ë¶ÎÉùÃ÷£¬ÇÒÔÚÎÄÕÂÒ³ÃæÃ÷ÏÔλÖøø³öÔ­ÎÄÁ¬½Ó¡£


Ïà¹ØÎĵµ£º

¡¶Îò͸javascript¡·Ñ§Ï°±Ê¼Ç£º¾Å¡¢Ô­Ðͱ϶

ÒýÑÔ
 
      prototypeÔ´×Ô·¨ÓÈí¼þ½çµÄ±ê×¼·­ÒëΪ“Ô­ÐÍ”£¬´ú±íÊÂÎïµÄ³õʼÐÎ̬£¬Ò²º¬ÓÐÄ£ÐͺÍÑù°åµÄÒâÒå¡£
 
prototypeÊôÐÔ
 
JavaScriptµÄËùÓÐfunctionÀàÐ͵ĶÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ¡£Õâ¸öprototypeÊôÐÔ±¾ÉíÓÖÊÇÒ»¸ö object ÀàÐ͵ĶÔÏó£¬Òò´ËÎÒÃÇÒ²¿ÉÒÔ¸ ......

javascriptʵÏÖÏñjava¡¢c#Ö®ÀàµÄsleepÔÝÍ£µÄº¯Êý¹¦ÄÜ

ÎÒÃǶ¼ÖªµÀjava¡¢c#¡¢vbµÈÓïÑÔ¶¼ÓÐsleepÔÝÍ£µÄº¯Êý£¬¶øJavaScript½Å±¾Ã»ÓÐÀàËƵŦÄÜ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄʵÏֵķ½·¨£º
<mce:script type="text/javascript"><!--
function test()
{
var s="javascript--ÔÝÍ£º¯Êý";
setTimeout(
function(){
eval(sleep(test)); //Ö´ÐÐreturnÖ®ºóµÄ´úÂ룬Ҳ¾ÍÊÇ&ldq ......

JavaScript½øÐÐGETºÍPOSTÇëÇó

JavaScript½øÐÐGETºÍPOSTÇëÇó
WebÉÏ×î³£¼ûµÄÇëÇó¾ÍÊÇGETÇëÇó.ÿ´ÎÔÚä¯ÀÀÆ÷ÖÐÊäÈëURL²¢´ò¿ªÒ²Ã×ÄÉÊÐ,¾ÍÊÇÔÚÏò·þÎñÆ÷·¢ËÍÒ»¸öGETÇëÇó.
GETÇëÇó£º
GETÇëÇóµÄ²ÎÊýʹÓÃÎʺÅ×·¼Óµ½URLµÄ½áβ,ºóÃ×ÄɸøÕâÓÃ&ºÃÁ¬½ÓÆðÀ´µÄÃû³Æ/Öµ.ÀýÈç:
http://www.somewhere.com/page.php?name1=value1&name2=value2&name3=value3
......

Javascript ÃæÏò¶ÔÏó»úÖƵÄʵÏÖ

Javascript ÃæÏò¶ÔÏó»úÖƵÄʵÏÖ
×Ô¶¨ÒåÀàµÄʵÏÖ·½·¨ºÜ¶à£¬Öصã̸Á½ÖÖ¡£
¹¹Ô캯Êý·¨
function Player(url){
    this.url = url;
   
    this.showUrl = function(){
        alert(this.url);
    }
 &nb ......

JavaScriptÖÐÄäÃûº¯Êý£¬º¯ÊýÖ±½ÓÁ¿ºÍ±Õ°ü(ת)

Ô­Îijö´¦: http://www.dnew.cn/post/196.htm
ÏÈ¿´ÏÂÏÂÃ漸ÖÖд·¨
1.function f(x){return x*x;};f(x);
2.(function(x){return x*x;})(x);
3.(function(x){return x*x;}(x));
µÚÒ»ÖÖÎÒÃÇÓ¦¸Ã¶¼ºÜÊìϤÁË£¬ÕâÊÇÎÒÃǾ­³£Ê¹ÓõÄд·¨¡£µÚ¶þµÚÈýÖÖ¶¼ÊÇÄäÃûº¯ÊýµÄд·¨¡£
------------------------------------------------ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ