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

javascriptдÀ෽ʽ֮һ

´ÓÕâƪÆ𣬻áÓÉdzµ½ÉîµÄ·ÖÎöjs OO֮дÀ෽ʽ£¬´ó¸Å»áÓÐ5-8ƪ¡£ºóÃæ½Ðø»á·ÖÎöÁ÷Ðп⣨¿ò¼Ü£©µÄдÀ෽ʽ¡£ÎªÁËÌÖÂ۵ĵ¥Ò»ÐÔ£¬Ôݲ»¿¼ÂÇÀàµÄ¼Ì³Ð£¬(˽ÓÐ,Êܱ£»¤)ÊôÐÔ»ò·½·¨¡£
EMCA262¹æ·¶ÖÐûÓÐÀà(class)µÄ¸ÅÄjsµÄnewÖ»ÊÇÈÃËû¿´ÆðÀ´¸üÏñc++,javaÒ»µã¡£ÕâÀï˵µÄдÀֻ࣬ÊÇÊéдjs´úÂë·ç¸ñ¶øÒÑ¡£
1¡¢¹¹Ô캯Êý·½Ê½
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
* @param {String} name
*/
function Person(name) {
this.name = name;
this.getName = function() {
return this.name;
}
}

ÕâÖÖ·ç¸ñÈÃÎÒÃÇÕâЩд¹ýjavaµÄÓеãÇ×ÇÐÔÚÓÚ¹¹ÔìÒ»¸ö¶ÔÏóÐèÒªÅäÖÃһЩ²ÎÊý£¬²ÎÊýÒª¸³Öµ¸øÀàÀïÃæthis¡£µ«ÓëjavaµÄÇø±ðÊÇjsÓÃfunctionÀ´¶¨ÒåÀ࣬²ÎÊýÒ²ÎÞÐ趨ÒåÀàÐÍ¡£
ÀàдºÃÁË£¬ÎÒÃÇÔ켸¸ö¶ÔÏó£º
var p1 = new Person("Jack");
var p2 = new Person("Tom");
console.log(p1 instanceof Person);//true
console.log(p2 instanceof Person);//true

¿ØÖÆ̨Êä³öÒ²Ö¤Ã÷ÁËp1£¬p2µÄÈ·ÊÇÀàPersonµÄ¶ÔÏóʵÀý¡£
ÕâÖÖ·½Ê½µÄÓŵãÊÇ£º¿ÉÒÔ¸ù¾Ý²ÎÊýÀ´¹¹Ô첻ͬµÄ¶ÔÏóʵÀý
£¬È±µãÊǹ¹Ôìʱÿ¸öʵÀý¶ÔÏ󶼻áÉú³ÉgetName·½·¨°æ±¾£¬Ôì³ÉÁËÄÚ´æµÄÀË·Ñ
¡£
µ±È»¾­Ñé·á¸»µÄ³ÌÐòÔ±ÓÃÒ»¸öÍⲿº¯ÊýÀ´´úÌæÀà·½·¨£¬´ïµ½ÁËÿ¸ö¶ÔÏó¹²Ïíͬһ¸ö·½·¨¡£¸ÄдºóµÄÀàÈçÏ£º
//Íⲿº¯Êý
function getName() {
return this.name;
}
function Person(name) {
this.name = name;
this.getName = getName;//×¢ÒâÕâÀï
}

ºÇºÇ£¬ÓÐÈË¿ÉÄܾõµÃ´úÂë·ç¸ñÓеã²îÇ¿ÈËÒ⣬Ôõô¿´Ò²Ã»ÓÐjavaÄÇô½ô´Õ¡£µ«µÄÈ·¿ÉÒÔ¼õÉÙÄÚ´æµÄÏûºÄ¡£


Ïà¹ØÎĵµ£º

Javascript µÄ´Ê·¨×÷ÓÃÓò¡¢µ÷ÓöÔÏóºÍ±Õ°ü

×÷ÓÃÓò Scope
Javascript Öеĺ¯ÊýÊôÓÚ´Ê·¨×÷ÓÃÓò£¬Ò²¾ÍÊÇ˵º¯ÊýÔÚËü±»¶¨ÒåʱµÄ×÷ÓÃÓòÖÐÔËÐжø²»ÊÇÔÚ±»Ö´ÐÐʱµÄ×÷ÓÃÓòÄÚÔËÐС£ÕâÊÇϬţÊéÉϵÄ˵·¨¡£µ«“¶¨Òåʱ”ºÍ“Ö´ÐУ¨±»µ÷Óã©Ê±”ÕâÁ½¸ö¶«Î÷ÓÐЩÈ˸㲻Çå³þ¡£¼òµ¥À´Ëµ£¬Ò»¸öº¯ÊýAÔÚ“¶¨Òåʱ”¾ÍÊÇ function A(){} Õâ¸öÓï¾äÖ´ÐеÄʱºò¾Í ......

ÔÚJavaÖÐʹÓÃjavascriptº¯Êý

JDK6ÒѾ­·¢²¼ºÜ¾ÃÁË£¬ºÜÔç¾ÍÌý¹ýËûÒѾ­Ö§³Ö½Å±¾ÓïÑÔÁË£¬²»¹ýһֱûÓÐʱ¼ä³¢ÊÔ£¬½ñÌì͵ÏÐÊÔÁËһϣ¬¸Ð¾õ²»´í¡£
¡¡¡¡javax.script°üËüÊÇJavaÐÂÔöµÄ²Ù×÷½Å±¾µÄ¹¤¾ß°ü£¬
¡¡¡¡ÀûÓÃËüÎÒÃÇ¿ÉÒԶԽű¾ÓïÑÔ½øÐвÙ×÷£¨±¾Àý½öÊÇÕë¶Ôjavascript
£©
¡¡¡¡1.ÓÃÒýÇæÖ±½Ó½âÎö½Å±¾¹«Ê½
¡¡¡¡Java´úÂë
¡¡¡¡//´´½¨½Å±¾ÒýÇæ¹ÜÀíÆ÷
¡¡¡¡Scri ......

javascript calendar

<SCRIPT>
//ÅжÏyÄêµÄÅ©ÀúÖÐÄǸöÔÂÊÇÈòÔÂ,²»ÊÇÈòÔ·µ»Ø0
function leapMonth(y){
return(lunarInfo[y-1900]&0xf);
}
var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0 ......

javascript Ô­ÐͶÔÏóÓëprototypeµÄ¹Øϵ

    JavascriptÖеļ̳лúÖÆÊÇËùνµÄÔ­ÐͶÔÏó¼Ì³Ð£¬Í¨¹ýÊôÐÔ·ÃÎÊ»úÖƵÄÌØÊâÐÔÀ´ÊµÏּ̳еġ£Ö®Ç°ÎÒÒ»Ö±ÒÔΪËùÓжÔÏóµÄÔ­ÐͶÔÏó¾ÍÊÇprototypeËùÖ¸µÄÄǸö¶ÔÏ󡣺óÀ´ÔÚ¿´javascriptÉè¼ÆģʽµÄʱºò·¢ÏÖ×÷Õß×¢ÖÐÓÐÒ»¾ä»°ÓëÎÒ֮ǰµÄÀí½â²»Í¬£¬Ëû˵“ÿ¸ö¶ÔÏó¶¼ÓÐÒ»¸öÔ­ÐͶÔÏ󣬵«Õâ²¢²»Òâζ×Åÿ¸ö¶ÔÏó¶¼ÓÐÒ»¸ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ