Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÈÃIFRAME¿ò¼ÜµÄ¸ß¶È×ÔÊÊÓ¦

Ò³ÃæÄÚǶ²»Í¬µÄÍøÒ³ÄÚÈÝʱ£¬µ¼ÖÂiframeµÄ¸ß¶ÈÎÞ·¨ÓëʵÏÖÄÚÈÝ»òä¯ÀÀÆ÷¸ß¶ÈÏàÆ¥Åä¡£´°¿Ú´óС±ä»»Ê±£¬²»ÄÜiframe²»ÄܽøÐÐ×Ô¶¯µ÷Õû¡£ÕâÀÎÒÃÇÀûÓÃJAVASCRIPTÈÃIFRAME¿ò¼ÜµÄ¸ß¶È×ÔÊÊÓ¦¡£
Ê×ÏÈ£¬Ð´³öÈçϵÄJS·½·¨¡£
/**
* ÄÚǶҳÃæµÄ¸ß¶ÈÉèÖÃ
*/
function handleFrameLoad() {
var hDoc = getBodyHeight(document);
var ......

javascript µÄ±Õ°ü

±Õ°ü£¨closure£©ÊÇJavascriptÓïÑÔµÄÒ»¸öÄѵ㣬ҲÊÇËüµÄÌØÉ«£¬ºÜ¶à¸ß¼¶Ó¦Óö¼ÒªÒÀ¿¿±Õ°üʵÏÖ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄѧϰ±Ê¼Ç£¬¶ÔÓÚJavascript³õѧÕßÓ¦¸ÃÊǺÜÓÐÓõġ£
Ò»¡¢±äÁ¿µÄ×÷ÓÃÓò
ÒªÀí½â±Õ°ü£¬Ê×ÏȱØÐëÀí½âJavascriptÌØÊâµÄ±äÁ¿×÷ÓÃÓò¡£
±äÁ¿µÄ×÷ÓÃÓòÎ޷ǾÍÊÇÁ½ÖÖ£ºÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿¡£
JavascriptÓïÑÔµÄÌØÊâÖ®´¦£¬¾ÍÔÚÓ ......

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

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

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

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