¡¶Îò͸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
Ïà¹ØÎĵµ£º
Ò»¡¢ºǫ́£¨.csÎļþ£©·½·¨£º
public string GetString(string name)
{
return ("Hello " + name);
}
&n ......
<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>
</ ......
¡¶Îò͸JavaScript¡·Ñ§Ï°±Ê¼Ç
ÔÎĵØÖ·£ºhttp://www.cnblogs.com/leadzen/archive/2008/02/25/1073404.html
ÕâÊÇÒ»±¾ºÜÐÎÏóÉú¶¯µÄÊ飬ʹÎÒÃÇ¿ÉÒÔ¸üÉîµØÁ˽âÁËJavaScript¡£
ÒýÑÔ
±à³ÌÊÀ½çÀïÖ»´æÔÚÁ½ÖÖ»ù±¾ÔªËØ£¬Ò»¸öÊÇÊý¾Ý£¬Ò»¸öÊÇ´úÂë¡£±à³ÌÊÀ½ç¾ÍÊÇÔÚÊý¾ÝºÍ´úÂëǧ˿ÍòÂƵ ......
ÒýÑÔ
ÈκÎÒ»¸öº¯Êý¶¼¿ÉÒÔΪÆ䶯̬µØÌí¼Ó»òÈ¥³ýÊôÐÔ£¬ÕâЩÊôÐÔ¿ÉÒÔÊǼòµ¥ÀàÐÍ£¬¿ÉÒÔÊǶÔÏó£¬Ò²¿ÉÒÔÊÇÆäËûº¯Êý¡£Ò²¾ÍÊÇ˵£¬º¯Êý¾ßÓжÔÏóµÄÈ«²¿ÌØÕ÷£¬ÄãÍêÈ«¿ÉÒ԰Ѻ¯Êýµ±¶ÔÏóÀ´Óá£Æäʵ£¬º¯Êý¾ÍÊǶÔÏó£¬Ö»²»¹ý±ÈÒ»°ãµÄ¶ÔÏó¶àÁËÒ»¸öÀ¨ºÅ“()”²Ù×÷·û£¬Õâ¸ö²Ù×÷·ûÓÃÀ´Ö´Ðк¯ÊýµÄÂß¼¡£¼´£¬º¯Êý±¾Éí»¹¿ÉÒÔ±»µ÷ ......