Javascript ÔÐͺͼ̳Ð(Prototypes and Inheritance)
Javascript ÔÐͺͼ̳Ð(Prototypes and Inheritance) ÊÕ²Ø
Ç°ÃæÎÒÃÇ¿´µ½ÁËÈçºÎʹÓà constructor À´³õʼ»¯¶ÔÏó¡£Èç¹ûÕâÑù×ö£¬ÄÇôÿһ¸ö´´½¨µÄжÔÏ󶼻á¶ÔÄÇЩÏàͬµÄÊôÐÔ£¬·½·¨½¨Á¢Ò»¸ö¶ÀÁ¢µÄ¸±±¾¡£¶øʵ¼ÊÉÏÓиü¼ÓÓÐЧµÄ·½·¨À´Ö¸¶¨·½·¨£¬³£Á¿£¬ÒÔ¼°ÆäËûһЩ¿É±»ËùÓиÃÀàµÄ¶ÔÏó¹²ÏíµÄÊôÐÔ¡£
JavaScript ¶ÔÏó´ÓÒ»¸öÔÐζÔÏó(prototype object) ¼Ì³ÐÊôÐÔ¡£ËùÓжÔÏó¶¼ÓÐÔÐÍ£»ÔÐ͵ÄËùÓÐÊôÐÔ¿´ÉÏÈ¥¾ÍÏñʹÓÃËü×÷ΪÔÐ͵ÄÄÇЩ¶ÔÏóµÄÊôÐÔÒ»Ñù¡£¼òµ¥µÄ˵¾ÍÊÇ£ºËùÓжÔÏ󶼴ÓËûµÄÔÐͼ̳ÐÊôÐÔ¡£
(each object inherits properties from its prototype).
¶ÔÏóµÄ prototype ͨ¹ýËüµÄ constructor function À´¶¨Òå¡£JavaScript ÀïËùÓÐµÄ function ¶¼ÓÐÒ»¸ö prototype ÊôÐÔ¡£Õâ¸öÊôÐÔ¿ªÊ¼Êǿյģ¬½ÓÏÂÀ´Äã¸øËûÌí¼ÓµÄÈκÎÊôÐÔ¶¼»á±» constructor ´´½¨µÄ¶ÔÏóËùÓµÓС£
prototype ¶ÔÏóºÍ constructor Ïà¹ØÁª¡£ÕâÒâζ×Å prototype ¿ÉÒÔ×÷Ϊ·ÅÖ÷½·¨ÒÔ¼°ÆäËû³£Á¿µÄÀíÏ볡Ëù¡£ÔÐÍÖеÄÊôÐÔ²»»á±»¸´ÖƵ½Ð´´½¨µÄ¶ÔÏóÖÐÈ¥£¬ËûÃǵÄÊôÐÔ¿´ÉÏÈ¥¾ÍÏñ¶ÔÏóµÄÊôÐÔÒ»Ñù¡£ÕâÒâζ×Å£¬Ê¹ÓÃÔÐÍÄܹ»´ó·ù¶ÈµÄ¼õÉÙ¶à¸öͬÀà¶ÔÏóÕ¼ÓõÄÄÚ´æ¡£
ÿһ¸ö class ¶¼Ö»ÓÐÒ»¸ö prototype object, ¸½´øÒ»Ì×ÊôÐÔ¡£µ«ÎÒÃÇÔÚÔËÐÐʱ¿ÉÄܻᴴ½¨¶à¸öÀàµÄʵÀý¡£ÄÇôÈç¹û·¢Éú¶ÔÔÐ͵ÄÊôÐԵĶÁд»á·¢ÉúʲôÇé¿ö£¿
µ±Äã¶ÁÒ»¸öÊôÐÔµÄʱºò£¬JavaScript Ê×Ïȳ¢ÊÔÈ¥²éÕÒ¶ÔÏó±¾ÉíÊÇ·ñÓÐÕâ¸öÊôÐÔ£¬Èç¹ûûÓУ¬½Ó×ÅÈ¥²éÕÒÔÐÍÀïÃæÊÇ·ñÓС£ÓеĻ°¾Í·µ»Ø½á¹û¡£
¶øµ±ÄãдÔÐ͵ÄÊôÐÔµÄʱºò£¬ÒòΪ¶à¸ö¶ÔÏó¹²ÏíÔÐÍ£¬ÏÔÈ»ÊDz»ÄÜÖ±½ÓÔÚÔÐÍÉϽøÐÐд²Ù×÷µÄ¡£Õâ¸öʱºòʵ¼ÊÉÏ JavaScript »áÔÚ¶ÔÏóÉÏ´´½¨Ò»¸öͬÃûµÄÊôÐÔ£¬È»ºó°Ñֵдµ½ÀïÃæ¡£µ±ÄãÏ´ζÁÕâ¸öÊôÐÔµÄʱºò£¬JavaScript Ò»ÏÂ×Ó¾ÍÔÚ¶ÔÏóµÄÊôÐÔÀï²éÕÒµ½ÁË£¬ÄÇô¾Í²»ÐèҪȥÔÐÍÀï²éÕÒÁË¡£Õâ¸öʱºò£¬ÎÒÃÇ˵“¶ÔÏóµÄÊôÐÔÑڸǻòÒþ²ØÁËÔÐ͵ÄÊôÐÔ”¡£(shadows or hides) ¡£
´ÓÉÏÃæÌÖÂÛ¿´³ö£¬ÆäʵÎÒÃÇÔÚÉè¼ÆÀàµÄʱºò£¬Ö»ÒªÕÆÎÕÒ»¸öÔÔò£ºÔÚÔÐÍÀï½ö¶¨ÒåһЩ·½·¨£¨·½·¨Ò»°ãÊDz»»á±äµÄ£©£¬³£Êý£¬³£Á¿µÈ¡£×öµ½ÕâÒ»µã¾Í²»ÈÝÒ×»ìÏýÁË¡£
Àý×Ó£º
// Define a constructor method for our class.
// Use it to initialize properties that will be different for
// each individual Circle object.
functionCircle(x, y, r)
{
this.x = x; // The X-coordinate of the center of the circle
this.y =
Ïà¹ØÎĵµ£º
function checkfiletype()
{
var fileName = document.getElementById('<%=FilePath.ClientID%>').value;
if (Trim(fileName)=="")
{
alert("ÇëÑ¡ÔñÒªÉÏ´«µÄÎļþ£¡");
......
ΪÁËÌá¸ßÍøÕ¾µÄ¼ÓÔØËٶȣ¬ÓÐÒ»¸öºÜÖØÒªµÄÊֶξÍÊÇÔÚÓû§ä¯ÀÀ¹ý³ÌÖеÄÉÏÓÎÍøÕ¾×öÒ»¸öÎļþµÄÔ¤¼ÓÔØ¡£Ô¤¼ÓÔØÎļþÒ»°ãÓÐÁ½ÖÖ³£Óõķ½Ê½£ºxhrºÍ¶¯Ì¬²åÈë½ÚµãµÄ·½Ê½¡£¶¯Ì¬²åÈë½ÚµãÊÇ×îΪ¼òµ¥Ò²×îΪ¹ã·ºµÄÒ»ÖÖÒì²½¼ÓÔØ·½Ê½(ÀýÈçyuiµÄGetÄ£¿é)£¬È»ºóʹÓö¯Ì¬²åÈë½Úµã·½·¨¼ÓÔصÄÎļþ¶¼»áÔÚ¼ÓÔغóÁ¢¼´Ö´ÐУ¬javascriptµÄÖ´ÐÐÒ»·½Ãæ»áÕ ......
1 javascript ÕýÔò
¶ÔÏó´´½¨ ºÍÓ÷¨
ÉùÃ÷javascript ÕýÔò
±í´ïʽ
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:
var reCat = new RegExp("cat");
ÄãÒ²¿ÉÒÔ
var reCat = /cat/; //Perl ·ç¸ñ £¨ÍƼö£©
2 ѧϰ×î³£ÓÃµÄ test exec match search replace split 6¸ö·½·¨
1£© test ¼ì²éÖ¸¶¨µÄ×Ö·û´®ÊÇ·ñ´æÔÚ
¸´ÖÆ´úÂë
......
´ò¿ªÇëÇó
¡¡¡¡ÓÐÁËÒªÁ¬½ÓµÄ URL ºó¾Í¿ÉÒÔÅäÖÃÇëÇóÁË¡£¿ÉÒÔÓà XMLHttpRequest ¶ÔÏóµÄ open() ·½·¨À´Íê³É¡£¸Ã·½·¨ÓÐÎå¸ö²ÎÊý:
request-type:·¢ËÍÇëÇóµÄÀàÐÍ¡£µäÐ͵ÄÖµÊÇ GET »ò POST£¬µ«Ò²¿ÉÒÔ·¢ËÍ HEAD ÇëÇó¡£
url:ÒªÁ¬½ÓµÄ URL¡£
asynch:Èç¹ûÏ£ÍûʹÓÃÒì²½Á¬½ÓÔòΪ true£¬·ñÔòΪ false¡£¸Ã²ÎÊýÊÇ¿ÉÑ¡µÄ£¬Ä¬ÈÏΪ true¡£
......
javascriptʼþÇý¶¯¿ò¼Ü ÊÕ²Ø
Ò»¸ö¼òµ¥µÄʼþÇý¶¯¿ò¼ÜµÄÑÝʾ£º
/*ControlDemo.js*/
//ʼþÇý¶¯¿ò¼Ü£¨ÑÝʾ£©
function ControlDemo(page)
{
//³õʼ»¯Page
if (page == null)
{
page = self;
}
if (page != self)
{
//Do sth. here...
}
&nb ......