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ÄÇô½ô´Õ¡£µ«µÄÈ·¿ÉÒÔ¼õÉÙÄÚ´æµÄÏûºÄ¡£
Ïà¹ØÎĵµ£º
calcu() ----º¯ÊýʵÏÖÁ½¸öÊýÏà³Ë
document.write(); ---´òÓ¡
document.calc.ÔªËØÃû.value; --»ñµÃ±íµ¥µÄÖµ
document.±íµ¥Ãû¡£±íµ¥ÔªËØÃû¡£value Ϊ±íµ¥¸³Öµ
¶¨Ò庯Êý£º
function Ãû×Ö()
{
//javaScriptÔ¤Óï¾ä
}
onClick="º¯ÊýÃû";  ......
JDK6ÒѾ·¢²¼ºÜ¾ÃÁË£¬ºÜÔç¾ÍÌý¹ýËûÒѾ֧³Ö½Å±¾ÓïÑÔÁË£¬²»¹ýһֱûÓÐʱ¼ä³¢ÊÔ£¬½ñÌì͵ÏÐÊÔÁËһϣ¬¸Ð¾õ²»´í¡£
¡¡¡¡javax.script°üËüÊÇJavaÐÂÔöµÄ²Ù×÷½Å±¾µÄ¹¤¾ß°ü£¬
¡¡¡¡ÀûÓÃËüÎÒÃÇ¿ÉÒԶԽű¾ÓïÑÔ½øÐвÙ×÷£¨±¾Àý½öÊÇÕë¶Ôjavascript
£©
¡¡¡¡1.ÓÃÒýÇæÖ±½Ó½âÎö½Å±¾¹«Ê½
¡¡¡¡Java´úÂë
¡¡¡¡//´´½¨½Å±¾ÒýÇæ¹ÜÀíÆ÷
¡¡¡¡Scri ......
ÓÃjavascriptÏÔʾXML
Äã¿ÉÒÔÓÃJavaScriptÏÔʾXML¡£¿ÉÒÔÓÃJavaScript (»ò VBScript)´ÓÒ»¸öXMLÎļþÖÐÊäÈëÊý¾Ý²¢ÔÚÒ»¸öHTMLÒ³ÃæÄÚÏÔʾXMLÊý¾Ý¡£ Òª¿´¿´XMLºÍHTMLÊÇÈçºÎÏ໥²¹³äµÄ£¬¿ÉÒÔÕâÑù×ö£ºÊ×ÏÈÕÒµ½XML Îĵµ(note.xml)£¬È»ºó´ò¿ªHTMLÎĵµ
(note.htm)£¬Õâ¸öHTMLÎĵµÖаüº¬ÁËÔĶÁX ......
×Ô¶¨ÒåÒ»¸ölogº¯Êý,Êä³ö´«È뺯ÊýµÄ¶ÔÏó»òÕßÐÅÏ¢.
Log.js
// JScript source code
function
log(category, message, object) {
// If this category is explicitly disabled, do nothing
if
(log.options[category + "Disabled
"]) return
;
// Find the container
var
id = categ ......
JavascriptÖеļ̳лúÖÆÊÇËùνµÄÔÐͶÔÏó¼Ì³Ð£¬Í¨¹ýÊôÐÔ·ÃÎÊ»úÖƵÄÌØÊâÐÔÀ´ÊµÏּ̳еġ£Ö®Ç°ÎÒÒ»Ö±ÒÔΪËùÓжÔÏóµÄÔÐͶÔÏó¾ÍÊÇprototypeËùÖ¸µÄÄǸö¶ÔÏ󡣺óÀ´ÔÚ¿´javascriptÉè¼ÆģʽµÄʱºò·¢ÏÖ×÷Õß×¢ÖÐÓÐÒ»¾ä»°ÓëÎÒ֮ǰµÄÀí½â²»Í¬£¬Ëû˵“ÿ¸ö¶ÔÏó¶¼ÓÐÒ»¸öÔÐͶÔÏ󣬵«Õâ²¢²»Òâζ×Åÿ¸ö¶ÔÏó¶ ......