Javascript Ö®prototypeÊôÐÔ
ÔÚjsÖУ¬Ã¿¸ö¶ÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ£º·µ»Ø¶ÔÏóÀàÐÍÔÐ͵ÄÒýÓ᣺ÜÞÖ¿Ú£¡Ï°Óï“ÒÀºù«»Æ°”£¬ÕâÀïµÄºù«¾ÍÊÇÔÐÍ£¬ÄÇô“ư.prototype” ·µ»ØµÄ¾ÍÊǺù«£¬»òÕߓư.prototype= new ºù«()”¡£
prototypeµÄÓÃ;£º
¼Ì³Ð
ÓÐÒ»¸ö¶ÔÏó££×ÓÀࣺ
function ×ÓÀà() {
this.lastname = "Samuel";
}
ÓÐÒ»¸ö¶ÔÏ󣣸¸Àࣺ
function ¸¸Àà() {
this.firstname = "Shen";
}
ÏÖÔÚ×ÓÀàÊÇÓÐÃûÎÞÐÕ£¬¸¸ÀàÊÇÓÐÐÕÎÞÃû£¬Èç¹û×ÓÀàÒªÓÐÃûÓÐÐյϰ£¬Ö»ÒªËµÃ÷££×ÓÀàµÄÔÐÍÊǸ¸Àࣣ¾Í¿ÉÒÔÁË£¬¼´×ÓÀà¼Ì³Ð×Ô¸¸Àࣺ
×ÓÀà.prototype = new ¸¸Àà();
ÖÁ´Ë£¬×ÓÀà¾Í²»ÔÙÊÇÓÐÃûÎÞÐÕÁË¡£
alert(×ÓÀà.firstname + " " + ×ÓÀà.lastname); //Samuel Shen
Ç£Ò»·¢¶ø¶¯È«Éí
¼ÈÈ»prototype·µ»ØµÄÊÇÔÐ͵ÄÒýÓã¬ÄÇôÈç¹û¸Ä±äÔÐ͵ϰ£¬ËùÓм̳Ð×Ô¸ÃÔÐ͵ĶÔÏó¶¼½«Êܵ½Ó°Ïì¡£
function Point(x,y) {
this.x = x;
this.y = y;
}
var p1 = new Point(1,2);
var p2 = new Point(3,4);
Point.prototype.z = 0; //¶¯Ì¬ÎªPointµÄÔÐÍÌí¼ÓÁËÊôÐÔ
alert(p1.z); //0
alert(p2.z); //0
/***************************************************************************/
function Person(name,sex) { //PersonÀàµÄ¹¹Ô캯Êý
this.name = name;
this.sex = sex;
}
Person.prototype.age = 12; //ΪPersonÀàµÄprototypeÊôÐÔ¶ÔÓ¦µÄprototype¶ÔÏóµÄÊôÐÔ¸³Öµ,
//Ï൱ÓÚΪPersonÀàµÄ¸¸ÀàÌí¼ÓÊôÐÔ
Person.prototype.print = function() { //ΪPersonÀàµÄ¸¸ÀàÌí¼Ó·½·¨
alert(this.name+"_"+this.sex+"_"+this.age);
};
var p1 = new Person("name1","male"); //p1µÄageÊôÐԼ̳Ð×ÓPersonÀàµÄ¸¸Àà(¼´prototype¶ÔÏó)
var p2 = new Person("name2","male");
p1.print(); //name1_male_12
p2.print(); //name2_male_12
p1.age = 34; //¸Ä±äp1ʵÀýµÄageÊôÐÔ p1ÊôÐÔÔÚ²»Ö¸ÏòPersonµÄprototypeÊôÐÔ
p1.print(); //name1_male_34
p2.print(); //name2_male_12
Person.prototype.age = 22; //¸Ä±äPersonÀàµÄ³¬ÀàµÄageÊôÐÔ
p1.print(); //name1_male_34(p1µÄageÊôÐÔ²¢
Ïà¹ØÎĵµ£º
Ïê̽TextRange¶ÔÏó--²éÕÒÓëÑ¡Ôñ
TextRange¶ÔÏóÊǶ¯Ì¬HTML(DHTML)µÄ¸ß¼¶ÌØÐÔ£¬Ê¹ÓÃËü¿ÉÒÔʵÏֺܶàºÍÎı¾ÓйصÄÈÎÎñ£¬ÀýÈçËÑË÷ºÍÑ¡ÔñÎı¾¡£Îı¾·¶Î§ÈÃÄú¿ÉÒÔÑ¡ÔñÐԵĽ«×Ö·û¡¢µ¥´ÊºÍ¾ä×Ó´ÓÎĵµÖÐÌôÑ¡³öÀ´¡£TextRange¶ÔÏóÊÇÔÚHTMLÎĵµ½«ÒªÏÔʾµÄÎı¾Á÷ÉϽ¨Á¢¿ªÊ¼ºÍ½áÊøÎ»ÖõijéÏó¶ÔÏó¡£
ÏÂÃæÊÇTextRangeµÄ³£ÓÃÊôÐÔÓë·½·¨£º
Ê ......
ÖØµãÔÚÓÚfunction scroll()£¬function clipShow()¼°ÒÔÏÂforÑ»·¡£
ÎÞ·ì¹ö¶¯ÐÂÎŵÄJavascriptÔ´´úÂ룬·ÅÔÚÕâÀÓÐÐèÒªµÄʱºò¿ÉÄÜÓõÃÉÏ£º
//CSSÑùʽ
<style>
.new_newsT{
padding-top: 10px;
padding-bottom: 8px;
}
.new_newsT .list {
CLEAR: both; MARGIN: 0px 6px 0px 10px
}
......
ÒòΪJSON ÊÇ javascript µÄÒ»¸ö×Ó¼¯£¬ËùÒÔ£¬ÔÚjavascript ÖÐʹÓÃJSONÊǷdz£¼òµ¥µÄ¡£
js ´úÂë
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method":&n ......
var myDate = new Date();
myDate.getYear(); //»ñÈ¡µ±Ç°Äê·Ý(2λ)
myDate.getFullYear(); //»ñÈ¡ÍêÕûµÄÄê·Ý(4λ,1970-????)
myDate.getMonth(); //»ñÈ¡µ±Ç°Ô·Ý(0-11,0´ú±í1ÔÂ)
myDate.getDate();   ......
1¡¢¶ÔÏóµÄ¼Ì³Ð£¬Ò»°ãµÄ×ö·¨ÊǸ´ÖÆ£ºObject.extend
prototype.jsµÄʵÏÖ·½Ê½ÊÇ£º
Object.extend = function(destination, source){
for (property in source) {
destination[property] = source[property];
}
return destination;
......