¡¶Îò͸javascript¡·Ñ§Ï°±Ê¼Ç£º¾Å¡¢ÔÐͱ϶
ÒýÑÔ
prototypeÔ´×Ô·¨ÓÈí¼þ½çµÄ±ê×¼·ÒëΪ“ÔÐÍ”£¬´ú±íÊÂÎïµÄ³õʼÐÎ̬£¬Ò²º¬ÓÐÄ£ÐͺÍÑù°åµÄÒâÒå¡£
prototypeÊôÐÔ
JavaScriptµÄËùÓÐfunctionÀàÐ͵ĶÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ¡£Õâ¸öprototypeÊôÐÔ±¾ÉíÓÖÊÇÒ»¸ö object ÀàÐ͵ĶÔÏó£¬Òò´ËÎÒÃÇÒ²¿ÉÒÔ¸øÕâ¸ö prototype ¶ÔÏóÌí¼ÓÈÎÒâµÄÊôÐԺͷ½·¨¡£¼ÈÈ» prototypeÊǶÔÏóµÄ“ÔÐÍ”£¬ÄÇôÓɸú¯Êý¹¹Ôì³öÀ´µÄ¶ÔÏóÓ¦¸Ã¶¼»á¾ßÓÐÕâ¸ö“ÔÐÍ”µÄÌØÐÔ¡£ÊÂʵÉÏ£¬ÔÚ¹¹Ô캯ÊýµÄprototypeÉ϶¨ÒåµÄËùÓÐÊôÐԺͷ½·¨£¬¶¼ÊÇ¿ÉÒÔͨ¹ýÆä¹¹ÔìµÄ¶ÔÏóÖ±½Ó·ÃÎʺ͵÷Óõġ£Ò²¿ÉÒÔÕâô˵£¬prototypeÌṩÁËһȺͬÀà¶ÔÏó¹²ÏíÊôÐԺͷ½·¨µÄ»úÖÆ¡£ÔËÐÐÈçÏ´úÂ룬Ȼºó¹Û²ì¡£
<script language="javascript">
function person(name){ //¹¹Ô캯Êýperson
this.name = name;
//this´´½¨³öµÄ¶ÔÏó£¬Ã¿Ò»¸ö¸±±¾¶¼»á°üº¬ÆäÊôÐԺͺ¯Êý
this.say = function(){alert("hello, i'm " + this.name);}
}
//prototype´´½¨µÄº¯Êý¶ÔÏó£¬ËùÓеĸ±±¾¹²Ïíͬһ¸öº¯Êý
person.prototype.show = function(){alert("hi~~, i'm " + this.name);}
var p1 = new person("p1");
var p2 = new person("p2");
alert(p1.say == p2.say); //false£¬Ã»¹²Ïíº¯Êý
alert(p1.show == p2.show); //true£¬¹²Ïíº¯Êý
</script>
ÔÐÍÁ´
<script language="javascript">
function person(name){
this.name = name;
}
person.prototype.say = function(){alert("hello, i'm " + this.name);}
function employee(name, salary){
//µ÷ÓÃperson×÷ΪemployeeµÄ¹¹Ô캯Êý——ÖØµã
person.call(this, name); //Ä¿µÄÊǼ̳ÐpersonµÄÊôÐÔ
this.salary = salary;
}
//×ÓÀ๹Ô캯ÊýÊ×ÏÈÐèÒªÓÃÉϲ㹹Ô캯ÊýÀ´½¨Á¢ prototype¶ÔÏó£¬ÊµÏּ̳еĸÅÄî——ÖØµã
employee.prototype = new person(); //Ä¿µÄÊǼ̳ÐpersonµÄ·½·¨£¬Ö»ÐèÒªÆä prototype µÄ·½·¨£¬´Ë¶ÔÏóµÄ³ÉԱûÓÐÈκÎÒâÒ壡
employee.prototype.showMoney = function(){alert(this.name + "'s salary is " + this.salary);}
var bill = new pers
Ïà¹ØÎĵµ£º
<html>
<body>
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr2 = new Array(3)
arr2[0] = "James"
arr2[1] = "Adrew"
arr2[2] = "Martin"
document.write(arr.concat(arr2))
</script>
</body>
</ ......
°æÈ¨ÉùÃ÷
£º¿ÉÒÔÈÎÒâ×ªÔØ£¬µ«×ªÔØÊ±±ØÐë±êÃ÷Ô×÷Õßcharlee¡¢ÔʼÁ´½Óhttp://tech.idv2.com/2006/11/23/javascript-strreplace-benchmark/
ÒÔ¼°±¾ÉùÃ÷¡£
¸ÐлClearΪÎÒÃÇÌṩÁËÕâ¸öЧÂʸü¸ßµÄ×Ö·û´®Ìæ»»º¯Êý
¡£ÕâÊǾ³£Ê¹ÓõÄHTMLÌØÊâ×Ö·ûÌæ»»º¯Êý£¬¼´½« &¡¢<¡¢>¡¢" µÈº¯ÊýÌæ»»³É &¡¢<¡¢>¡¢&qu ......
response.write "<script language='javascript'>"
response.write "alert('Óû§Ãû»òÃÜÂë´íÎó!');"
response.write "hist ......
ÒýÑÔ
ÒªÀí½â JavaScript£¬ÄãµÃÊ×ÏÈ·Å϶ÔÏóºÍÀàµÄ¸ÅÄ»Øµ½Êý¾ÝºÍ´úÂëµÄ±¾Ô¡£Ç°ÃæËµ¹ý£¬±à³ÌÊÀ½çÖ»ÓÐÊý¾ÝºÍ´úÂëÁ½ÖÖ»ù±¾ÔªËØ£¬¶øÕâÁ½ÖÖÔªËØÓÖÓÐמÀ²ø²»ÇåµÄ¹ØÏµ¡£JavaScript¾ÍÊǰÑÊý¾ÝºÍ´úÂë¶¼¼ò»¯µ½×îÔʼµÄ³Ì¶È¡£
»ù±¾ÀàÐÍ
Ò»¡¢¼òµ¥Êý¾ÝÀàÐÍ£ºundefined¡¢null¡¢boolean¡¢number¡¢string£¨×¢Ò⣺¶¼Ê ......
ÒýÑÔ
ÔÙÀ´¿´¿´functionÓëobjectµÄ³¬È»½áºÏ°É¡£
ÔÚÃæÏò¶ÔÏóµÄ±à³ÌÊÀ½çÀÊý¾ÝÓë´úÂëµÄÓлú½áºÏ¾Í¹¹³ÉÁ˶ÔÏóµÄ¸ÅÄî¡£×Ô´ÓÓÐÁ˶ÔÏ󣬱à³ÌÊÀ½ç¾Í±»»®·Ö³ÉÁ½²¿·Ö£¬Ò»¸öÊǶÔÏóÄÚµÄÊÀ½ç£¬Ò»¸öÊǶÔÏóÍâµÄÊÀ½ç¡£¶ÔÏóÌìÉú¾ßÓÐ×Ô˽µÄÒ»Ãæ£¬ÍâÃæµÄÊÀ½çδ¾ÔÊÐíÊDz»¿É·ÃÎʶÔÏóÄÚ²¿µÄ¡£¶ÔÏóÒ²Óдó ......