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

javascript Ö® Closure

http://javascript.crockford.com/private.html
function a() {
var i = 0;
function b() {
alert(++i);
}
return b;
}
var c = a();
c();
 
µ±ÔÚº¯ÊýbÖзÃÎÊÒ»¸ö±äÁ¿µÄʱºò£¬ËÑË÷˳ÐòÊÇ£º
ÏÈËÑË÷×ÔÉíµÄ»î¶¯¶ÔÏó£¬Èç¹û´æÔÚÔò·µ»Ø£¬Èç¹û²»´æÔÚ½«¼ÌÐøËÑË÷º¯ÊýaµÄ»î¶¯¶ÔÏó£¬ÒÀ´Î²éÕÒ£¬Ö±µ½ÕÒµ½ÎªÖ¹¡£
Èç¹ûº¯Êýb´æÔÚprototypeÔ­ÐͶÔÏó£¬ÔòÔÚ²éÕÒÍê×ÔÉíµÄ»î¶¯¶ÔÏóºóÏȲéÕÒ×ÔÉíµÄÔ­ÐͶÔÏó£¬ÔÙ¼ÌÐø²éÕÒ¡£Õâ¾ÍÊÇJavascriptÖеıäÁ¿²éÕÒ»úÖÆ¡£
Èç¹ûÕû¸ö×÷ÓÃÓòÁ´É϶¼ÎÞ·¨ÕÒµ½£¬Ôò·µ»Øundefined¡£
function Container(param) {
this.member = param;
}
var myContainer = new Container('abc'); //member='abc'
Container.prototype.stamp = function (string) {
return this.member + string;
}
myContainer.stamp('def') //member='abcdef'
function Container(param) {
//private method
function dec() {
if (secret > 0) {
secret -= 1;
return true;
} else {
return false;
}
}
this.member = param;
var secret = 3;
var that = this;
//privileged method
this.service = function () {
if (dec()) {
return that.member;
} else {
return null;
}
};
}
myContainer.service() //abc(first) null(second.....)


Ïà¹ØÎĵµ£º

Àí½â JavaScript ±Õ°ü{תÔØ}

¡¾×ª¡¿http://www.cnblogs.com/chenxizhang/archive/2010/01/02/1638010.html
±¾ÎÄתÔØ×Ô£ºhttp://www.cn-cuckoo.com/2007/08/01/understand-javascript-closures-72.html
Òª³ÉΪ¸ß¼¶ JavaScript ³ÌÐòÔ±£¬¾Í±ØÐëÀí½â±Õ°ü¡£
±¾ÎĽáºÏ ECMA 262 ¹æ·¶Ïê½âÁ˱հüµÄÄÚ²¿¹¤×÷»úÖÆ£¬Èà JavaScript ±à³ÌÈËÔ±¶Ô±Õ°üµÄÀí½â´Ó&ldquo ......

ÈçºÎÔÚjavascriptÖзÃÎÊÒ³Ã涨ÒåµÄ±äÁ¿

¡¾×ª¡¿http://www.cnblogs.com/chenxizhang/archive/2010/01/01/1637309.html
Èç¹ûÎÒÃÇÐèÒªÔÚjavascript·ÃÎʵ½Ò³ÃæÖж¨ÒåµÄ±äÁ¿£¬´óÖÂÊÇÈçϵÄÓï·¨
//ÕâÊÇ2010Äê1ÔÂ1ÈÕÔö¼ÓµÄ´úÂë
var ismanager = "<%= DepartManager %>";
if (ismanager == "true") {
$(" ......

ÈçºÎΪjavascript´úÂë±àдעÊÍÒÔÖ§³ÖÖÇÄܸÐÖª

¡¾×ª¡¿http://www.cnblogs.com/chenxizhang/archive/2009/07/12/1522058.html
ÔÚʹÓÃVisual Studio×ö¿ª·¢µÄʱºò£¬ÖÇÄܸÐÖªÊǷdz£·½±ãµÄ¡£´ÓVS2008¿ªÊ¼£¬ÌṩÁ˶ÔjavascriptµÄÖÇÄܸÐÖªÖ§³Ö¡£ÀýÈç

ÉÏÊö´úÂëÖУ¬ÎÒÃÇÏÈÓÃdocument¶ÔÏóµÄgetElementByIdµÄ·½Ê½È¡µÃÁËÎĵµÖеÄÒ»¸öIdΪform1µÄÔªËØ£¬Êµ¼ÊÉϾÍÊÇĬÈϵÄÄǸö´°ÌåÔ ......

JavaScript apply¡¢call·½·¨ºÍlengthÊôÐÔ

JavaScriptΪº¯Êý¶ÔÏó¶¨ÒåÁËÁ½¸ö·½·¨£ºapplyºÍcall£¬ËüÃǵÄ×÷Óö¼Êǽ«º¯Êý°ó¶¨µ½ÁíÍâÒ»¸ö¶ÔÏóÉÏÈ¥ÔËÐУ¬Á½Õß½öÔÚ¶¨Òå²ÎÊýµÄ·½Ê½ÓÐËùÇø±ð£º
Function.prototype.apply(thisArg,argArray);
Function.prototype.call(thisArg[,arg1[,arg2…]]);
´Óº¯ÊýÔ­ÐÍ¿ÉÒÔ¿´µ½£¬µÚÒ»¸ö²ÎÊý¶¼±»È¡ÃûΪthisArg£¬¼´ËùÓк¯ÊýÄÚ²¿µ ......

JavaScriptÄÚ´æй©

1¡¢Ê²Ã´ÊDZհü¡¢ÒÔ¼°±Õ°üËùÉæ¼°µÄ×÷ÓÃÓòÁ´ÕâÀï¾Í²»ËµÁË¡£
2¡¢JavaScriptÀ¬»ø»ØÊÕ»úÖÆ 
     JavaScript²»ÐèÒªÊÖ¶¯µØÊÍ·ÅÄڴ棬ËüʹÓÃÒ»ÖÖ×Ô¶¯À¬»ø»ØÊÕ»úÖÆ£¨garbage collection£©¡£µ±Ò»¸ö¶ÔÏóÎÞÓõÄʱºò£¬¼´³ÌÐòÖÐÎÞ±äÁ¿ÒýÓÃÕâ¸ö¶ÔÏóʱ£¬¾Í»á´ÓÄÚ´æÖÐÊͷŵôÕâ¸ö±äÁ¿¡£
 
Code
 &nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ