javascriptÉè¼Æģʽ_µÚ¶þ²¿·Ö_µ¥Ìåģʽ
µ¥Ìåģʽ
Óŵã:°Ñ´úÂë×éÖ¯µÃÒ»Ö²¢¸ôÀë,¸üÈÝÒ×ÔĶÁºÍά»¤,Ìá¸ßÎȶ¨ÐÔ;ÓÃÓÚÓÅ»¯,ÌáÉýÐÔÄÜ
ȱµã:¿Éµ¼ÖÂÇ¿ñîºÏ
5.1 µ¥ÌåµÄ»ù±¾½á¹¹
var Singleton = {
attribute1 : true,
attribute2 : 10,
method1 : function(){},
method2 : function(){}
};
Ñϸñ°´¶¨ÒåÀ´Ëµ,C1²»ÊÇÒ»¸öµ¥Ìå,ÒòΪËü²»ÊÇÒ»¸ö¿ÉʵÀý»¯µÄÀà
¶ÔÏó×ÖÃæÁ¿Ö»ÊÇ´´Òâµ¥ÌåµÄ·½Ê½Ö®Ò».
²¢·ÇËùÓеĶÔÏó×ÖÃæÁ¿¶¼Êǵ¥Ìå,Ö»ÓÃÀ´Ä£·Â¹ØÁªÊý×é¼°ÈÝÄÉÊý¾ÝµÄ¾Í²»Êǵ¥Ìå.
5.2 »®·ÖÃüÃû¿Õ¼ä
var MyNamespace = {}
MyNamespace.common = {};
5.3 ÓÃ×÷Ìض¨ÍøҳרÓôúÂëµÄ°ü×°Æ÷µÄµ¥Ìå
GiantCorp.RegPage = {
FORM_ID : 'reg-form',
//method
handSubmit : function(e){
e.preventDefault();
//...
GiantCorp.RegPage.sendRegistration();
},
init : function(){
GiantCorp.RegPage.formEl = $(GiantCorp.RegPage.FORM_ID);
addEvent(GiantCorp.RegPage.formEl,'submit',GiantCorp.RegPage.handSubmit);
}
};
addLoadEvent(GiantCorp.RegPage.init);
//ÒÔÉÏ´úÂ뽫ÊôÐÔ¼°·½·¨¶¼Í³Ò»µ½Ò»¸öµ¥ÌåÖÐ,²¢Í¨¹ýinitÀ´°ó¶¨Ê¼þ,×îºóÔÚÒ³ÃæÉϵ÷ÓÃinit¼´¿ÉʵÏÖÌض¨Ò³ÃæµÄʹÓÃ
ijÍøҳרÓôúÂë,×îºÃâÊÔÚ×Ô¼ºµÄµ¥Ìå¶ÔÏóÖÐ
5.4 ÓµÓÐ˽ÓóÉÔ±µÄµ¥Ìå
1) Ï»®Ïß±íʾ·¨
GiantCorp.DataParser = {
//Private methods
_stripWhitespace : function(str){
return str.replace(/\s+/,'');
},
_stringSplit : function(str,delimiter){
return str.split(delimiter);
},
//Public method
stringToArray : function(str, delimiter,stripWS){
if(stripWS){
str = this._stripWhitespace(str);
}
var outputArray = this._stringSplit(str,delemiter);
return outputArray;
}
}
2) ʹÓñհü
MyNamespace.Singleton = (function(){
return {};
})();
ÕâÖÖ·½Ê½ÓëÖ±½ÓʹÓöÔÏó×ÖÃæÁ¿Ã»Ê²Ã´Çø±ð,µ«Õâ¸ö°ü×°º¯Êý´´½¨ÁËÒ»¸ö¿ÉÒÔÓÃÀ´Ìí¼Ó˽ÓóÉÔ±µÄ±Õ°ü,ÈκÎÌí¼ÓÔÚÕâ¸öÄäÃûº¯ÊýÖжø²»ÔÚ¶ÔÏó×ÖÃæÁ¿ÖеĶ¼½«³ÉΪ˽ÓгÉÔ±
MyNamespace.Singleton = (function(){
//Private members
var p1 = false;
var p2 = 10;
function p3(){}
return {
//Public members
pub1 : true,
pub2 : 10,
pub3 : functi
Ïà¹ØÎĵµ£º
¼¸ºõÿ¸ö¿ª·¢ÈËÔ±¶¼ÓÐÃæÏò¶ÔÏóÓïÑÔ£¨±ÈÈçC++¡¢C#¡¢Java£©µÄ¿ª·¢¾Ñé¡£ ÔÚ´«Í³ÃæÏò¶ÔÏóµÄÓïÑÔÖУ¬ÓÐÁ½¸ö·Ç³£ÖØÒªµÄ¸ÅÄî - ÀàºÍʵÀý¡£
ÀඨÒåÁËÒ»ÀàÊÂÎ﹫¹²µÄÐÐΪºÍ·½·¨£»¶øʵÀýÔòÊÇÀàµÄÒ»¸ö¾ßÌåʵÏÖ¡£ ÎÒÃÇ»¹ÖªµÀ£¬ÃæÏò¶ÔÏó±à³ÌÓÐÈý¸öÖØÒªµÄ¸ÅÄî - ·â×°¡¢¼Ì³ÐºÍ¶à̬¡£
µ«ÊÇÔÚJavaScriptµÄÊÀ½çÖУ¬ËùÓеÄÕâÒ»ÇÐÌØ ......
JavascriptË¢ÐÂÒ³ÃæµÄ¼¸ÖÖ·½·¨£º
³ÌÐò´úÂë
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refres ......
½ñÌìÔÚ²©¿ÍÔ°ÉÏ¿´µ½Ò»ÆªÎÄÕ£¬¸ú×ÅѧϰÁËһϣ¬×ª¹ýÀ´Óë´ó¼Ò·ÖÏí£¬²¿·ÖÄÚÈÝÎÒ×öÁ˲¹³ä£¡
Ò»¡¢JavaScriptÕýÔò±í´ïʽ»ù±¾ÖªÊ¶
1¡¢JavaScriptÕýÔò±í´ïʽ´´½¨ºÍÓ÷¨
ÉùÃ÷ÕýÔò±í´ïʽÓÐÁ½ÖÖ·½Ê½£º
a) var reCat = new RegExp("cat");
b) var reCat = /cat/; //perl·ç¸ñ£¨ÍƼö£©& ......
ÈçºÎÀûÓÃÍøÒ³µ¯³ö¸÷ÖÖÐÎʽµÄ´°¿Ú£¬ÎÒÏë´ó¼Ò´ó¶à¶¼ÊÇÖªµÀЩµÄ£¬µ«ÄÇÖÖ¶àÖÖ¶àÑùµÄµ¯³öʽ´°¿ÚÊÇÔõô¸ã³öÀ´µÄ£¬ÎÒÃǽñÌì¾ÍÀ´Ñ§Ï°Ò»Ï£º 1.µ¯ÆôÒ»¸öÈ«ÆÁ´°¿Ú
;
www.kunde58.com
2.µ¯ÆôÒ»¸ö±»F11»¯ºóµÄ´°¿Ú
;
www.kunde58.com
3.µ¯ÆôÒ»¸ö´øÓÐÊÕ²ØÁ´½Ó¹¤¾ßÀ¸µÄ´°¿Ú ......
±¾ÎĽéÉÜÈçϼ¸¸ö·½ÃæµÄÄÚÈÝ:
1.ÈçºÎ´´½¨Êý×é
2.ÈçºÎ¶ÔÊý×é½øÐвÙ×÷£¨Ìí¼Ó,ɾ³ý,¶ÁÈ¡)
3.Êý×é³£¼û·½·¨ºÍÊôÐÔ
ÈçºÎ´´½¨Ò»¸öÊý×é,Ò»°ãµØ¸ù¾Ý³õʼ»¯É趨¼òµ¥·ÖΪ3ÖÖ:
1.µ¥´¿´´½¨Êý×é:
var arr=new Array();
Òªµã:ÓÃnew¹Ø¼ü×Ö´´½¨Êý×é¶ÔÏóArray(),Array()¶ÔÏóÊÇÒ»¸ö±¾µØÀà,¿ÉÒÔÓÃnew´´½¨Ò»¸ö¶ÔÏóºóʹÓÃ
2.´´½¨Êý×éµÄÍ ......