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

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ÊôÐÔ²¢


Ïà¹ØÎĵµ£º

javascriptÖеÄmoveStartºÍmoveEnd·½·¨

Ïê̽TextRange¶ÔÏó--²éÕÒÓëÑ¡Ôñ
TextRange¶ÔÏóÊǶ¯Ì¬HTML(DHTML)µÄ¸ß¼¶ÌØÐÔ£¬Ê¹ÓÃËü¿ÉÒÔʵÏֺܶàºÍÎı¾ÓйصÄÈÎÎñ£¬ÀýÈçËÑË÷ºÍÑ¡ÔñÎı¾¡£Îı¾·¶Î§ÈÃÄú¿ÉÒÔÑ¡ÔñÐԵĽ«×Ö·û¡¢µ¥´ÊºÍ¾ä×Ó´ÓÎĵµÖÐÌôÑ¡³öÀ´¡£TextRange¶ÔÏóÊÇÔÚHTMLÎĵµ½«ÒªÏÔʾµÄÎı¾Á÷ÉϽ¨Á¢¿ªÊ¼ºÍ½áÊøÎ»ÖõijéÏó¶ÔÏó¡£
ÏÂÃæÊÇTextRangeµÄ³£ÓÃÊôÐÔÓë·½·¨£º
Ê ......

ÎÞ·ì¹ö¶¯ÐÂÎŵÄJavascriptÔ´´úÂë

ÖØµãÔÚÓÚ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
} ......

ÔÚjavascript ÖÐʹÓÃJSON

ÒòΪJSON ÊÇ javascript µÄÒ»¸ö×Ó¼¯£¬ËùÒÔ£¬ÔÚjavascript ÖÐʹÓÃJSONÊǷdz£¼òµ¥µÄ¡£
   
   
js ´úÂë
 
var myJSONObject = {"bindings": [  
        {"ircEvent": "PRIVMSG", "method":&n ......

JavaScriptµÄÈÕÆÚ´¦Àí

var myDate = new Date();
myDate.getYear();        //»ñÈ¡µ±Ç°Äê·Ý(2λ)
myDate.getFullYear();    //»ñÈ¡ÍêÕûµÄÄê·Ý(4λ,1970-????)
myDate.getMonth();       //»ñÈ¡µ±Ç°Ô·Ý(0-11,0´ú±í1ÔÂ)
myDate.getDate();    ......

Javascript Ö®apply()

1¡¢¶ÔÏóµÄ¼Ì³Ð£¬Ò»°ãµÄ×ö·¨ÊǸ´ÖÆ£ºObject.extend
prototype.jsµÄʵÏÖ·½Ê½ÊÇ£º
Object.extend = function(destination, source){
for (property in source) {
destination[property] = source[property];
}
return destination;
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ