JavaScriptÃæÏò¶ÔÏó³ÌÐòÉè¼Æ(6): ·â×°
±¾²©¿ÍתÔØÓÚ£ºhttp://devbean.javaeye.com/blog/407517
·â×°ÊÇÃæÏò¶ÔÏóµÄÖØÒª¸ÅÄîÖ®Ò»¡£Èç¹ûÒ»¸ö³ÌÐòûÓзâ×°ÐÔ£¬Ò²¾Í̸²»ÉÏʲôÃæÏò¶ÔÏó¡£µ«ÊÇ£¬JavaScript²¢²»ÏñÆäËûµÄÓïÑÔ£¬±ÈÈçJava£¬Óй«ÓбäÁ¿ºÍ˽ÓбäÁ¿µÈ£»ÔÚJavaScriptÖÐÖ»ÓÐÒ»ÖÖ×÷ÓÃÓò£º¹«ÓÐ×÷ÓÃÓò¡£ÔÚ±¾ÕÂÖУ¬ÎÒÃǽ«»á¼ûʶµ½JavaScriptÊÇÈçºÎʵÏÖ·â×°µÄÌØÐԵġ£
1. thisºÍ¹«ÓбäÁ¿
Ê×ÏÈÐèÒªÀí½âthis¹Ø¼ü×Ö¡£¿´ÏÂÃæµÄÒ»¶Î´úÂ룬ÄãÓ¦¸Ã¶Ô´Ë¸Ðµ½ÊìϤ£º
Js´úÂë
function Person(name, age) {
this.name = name; // ¶¨ÒåÒ»¸ö¹«ÓбäÁ¿
this.age = age;
this.show = function() { // ¶¨ÒåÒ»¸ö¹«Óк¯Êý
alert("name: " + name + "; age: " + age);
}
}
var bill = new Person("Bill", 20);
alert(bill.name);
bill.show();
ÕâÀïµÄthis¹Ø¼ü×ÖÊDZز»¿ÉÉٵġ£Ç°ÃæÖ»ÊÇÈôó¼Ò¼Çס£¬ÄÇôΪʲôҪÕâÑùÄØ£¿ÏëÏëJavaScriptµÄ¶ÔÏó£¬JavaScriptµÄ¶ÔÏóÀàËÆÓÚÉ¢ÁУ¬Ò»¸ö<string, object>¼ü-Öµ¶ÔµÄ¼¯ºÏ¡£ÕâÀïµÄ¶ÔÏóµÄÊôÐÔʵ¼ÊÉ϶¼ÊÇÀëÉ¢µÄ£¬²¢²»ÏñÆäËûµÄÓïÑÔÄÇÑù°ó¶¨µ½Ò»¸ö¶ÔÏóÉÏÃæ¡£this¹Ø¼ü×ÖÖ¸´úµÄÊÇÊôÐÔ»òÕߺ¯ÊýµÄµ÷ÓÃÕߣ¬Ò²¾ÍÊÇ˵£¬Ëµ÷ÓÃÕâ¸öÊôÐÔ»òÕߺ¯ÊýÖ¸µÄ¾ÍÊÇË¡£¿ÉÒÔ¿´µ½£¬ÕâÀïµÄthisºÍJava»òÕßC++µÄthisÊÇÓÐËù²»Í¬µÄ£¬ºóÕßµÄthisÊÇÖ¸ÊôÐÔ»òÕߺ¯ÊýËùÔÚµÄÄǸö¶ÔÏó±¾Éí¡£¶øÕâÀïthisµÄ×÷ÓþÍÊǽ«ËüºóÃæ¸ú×ŵÄÊôÐÔ»òÕ߶ÔÏó°ó¶¨µ½µ÷ÓÃÕßÉÏÃæ¡£»ØÒäÒ»ÏÂJavaScriptµÄnewµÄ¹ý³Ì£¬Ê×ÏȽ«´´½¨Ò»¸ö¿ÕµÄ¶ÔÏó£¬È»ºóʹÓù¹Ô캯Êý³õʼ»¯Õâ¸ö¶ÔÏó£¬×îºó·µ»ØÕâ¸ö¶ÔÏó¡£ÔÚÕâ¸ö¹ý³ÌÖУ¬JavaScript½«°ÑthisÓÃÕâ¸ö¶ÔÏóÌæ»»£¬Ò²¾ÍÊǰѶÔÏóºÍÕâЩÊôÐÔ»òº¯ÊýÏà¹ØÁª£¬¿´ÉÏÈ¥¾ÍÏñÊÇÕâ¸öµ÷ÓÃÕßÓµÓÐÕâ¸öÊôÐÔ»òÕߺ¯ÊýËƵģ¬ÆäʵÕâÊÇthisµÄ×÷Óá£
ÕâÑù¿´À´£¬showÀïÃæµÄnameºÍage²¢Ã»Óйؼü×Ö£¬µ«Ò²ÊÇ¿ÉÒÔÕý³£µÄÖ´ÐоͻáÃ÷°×Ôõô»ØÊÂÁË——ÒòΪǰÃæÒѾÓÃthis°ÑnameºÍageÓëÕâ¸ö¶ÔÏóbillÏà¹ØÁª£¬²¢ÇÒ£¬showÒ²¹ØÁªµ½Õâ¸öbill±äÁ¿£¬Òò´ËJavaScriptÊÇ¿ÉÒÔÕÒµ½ÕâÁ½¸ö±äÁ¿µÄ¡£
ÕâÑùÀ´¿´£¬ËƺõÓÉthisÐÞÊεĶ¼Êǹ«ÓбäÁ¿¡£ÊÂʵȷʵÈç´Ë£¬Èç¹ûÄãҪʹһ¸ö±äÁ¿³ÉΪ¹«ÓбäÁ¿£¬¿ÉÒÔʹÓÃthis¡£ÏñÉÏÃæ´úÂëÖеÄnameºÍage¶¼Êǹ«ÓбäÁ¿£¬ÔÚÍâÃæʹÓÃaPerson.name»òÕßaPerson.age¾Í¿ÉÒÔ·ÃÎʵ½¡£
2. ˽ÓбäÁ¿
ÔõôÉùÃ÷Ò»¸ö˽ÓбäÁ¿ÄØ£¿ÊÂʵÉϾÍÏñÇ°Ãæ˵µÄ£¬JavaScript¸ù±¾Ã»ÓÐ˽ÓÐ×÷ÓÃÓòÕâһ˵¡£ÄÇôÀ´¿´ÏÂÃæµÄ´úÂ룺
Js´úÂë
function Person(name, age) {
var name = nam
Ïà¹ØÎĵµ£º
scrollHeight: »ñÈ¡¶ÔÏóµÄ¹ö¶¯¸ß¶È¡£
scrollLeft:ÉèÖûò»ñȡλÓÚ¶ÔÏó×ó±ß½çºÍ´°¿ÚÖÐÄ¿Ç°¿É¼ûÄÚÈݵÄ×î×ó¶ËÖ®¼äµÄ¾àÀë
scrollTop:ÉèÖûò»ñȡλÓÚ¶ÔÏó×¶ËºÍ´°¿ÚÖпɼûÄÚÈݵÄ×¶ËÖ®¼äµÄ¾àÀë
scrollWidth:»ñÈ¡¶ÔÏóµÄ¹ö¶¯¿í¶È
offsetHeight:»ñÈ¡¶ÔÏóÏà¶ÔÓÚ°æÃæ»òÓɸ¸×ø±ê offsetParent ÊôÐÔÖ¸¶¨µÄ¸¸×ø±êµÄ¸ß¶È
offsetL ......
1.×Ôhttp://jorkin.reallydo.com/article.asp?id=275
µÚÒ»´Î·¢ÏÖJavaScriptÖÐreplace() ·½·¨Èç¹ûÖ±½ÓÓÃstr.replace("-","!") Ö»»áÌæ»»µÚÒ»¸öÆ¥ÅäµÄ×Ö·û.
¶østr.replace(/\-/g,"!")Ôò¿ÉÒÔÈ«²¿Ìæ»»µôÆ¥ÅäµÄ×Ö·û(gΪȫ¾Ö±êÖ¾)¡£
replace()
The replace() method returns the string that results when you replac ......
Javascript ±¾Éí²¢²»Ö±½ÓÖ§³Ö¼Ì³Ð£¬²»¹ýjavascriptÇ¿´óÖ®´¦¾ÍÔÚÓÚÆäÎޱȵÄÁé»îÐÔ£¬Äã»ù±¾¿ÉÒÔΪËùÓûΪ¡£
1. ͨ¹ýÔÚ×ÓÀàÖе÷Óø¸ÀàµÄ¹¹½¨º¯ÊýÀ´ÊµÏּ̳С£
2. ÓÃPrototypeÀ´ÊµÏּ̳С£
3. ³£¼ûframeworkÊÇÈçºÎʵÏּ̳еġ£
4. ×ܽá ......
ÔںܶàÓïÑÔÖУ¬º¯Êý(JavaÀïÃæ³ÉΪ·½·¨)ºÍ¶ÔÏóʱ½ØÈ»²»Í¬µÄÁ½ÖÖ¶«Î÷¡£º¯Êý±»¶¨ÒåΪ¶ÔÏóµÄ¶¯×÷£¬»òÕßÊÇÈ«¾ÖµÄ(ÏñÔÚC++ÖеÄmainº¯ÊýÒ»Ñù)¡£µ«ÊÇÔÚJavaScriptÖУ¬º¯ÊýºÍ¶ÔÏóµÄ½çÏÞÈ´ÏԵò»ÄÇôÃ÷ÏÔ¡£
1. º¯ÊýµÄ¶¨Òå
JavaScriptÖÐÓкܶàÖÖ¶¨Ò庯ÊýµÄ·½·¨£º
Js´úÂë
function hello() { alert("Hello!"); }
var hello1 ......
±¾²©¿ÍתÔØÓÚ £ºhttp://devbean.javaeye.com/blog/406265
ÀàÊÇÃæÏò¶ÔÏó³ÌÐòÉè¼ÆµÄºËÐĸÅÄîÖ®Ò»¡£Ò»¸öÀà´ú±íÁ˾ßÓÐÏàËÆÊôÐÔµÄÒ»ÀàÊÂÎïµÄ³éÏó¡£´Ó±¾Æª¿ªÊ¼£¬ÎÒÃǽ«ÕýʽµÄ½øÈëJavaScriptµÄÃæÏò¶ÔÏ󲿷֡£Ê×ÏÈÐèҪעÒâµÄÊÇ£¬ÔÚJavaScriptÖв¢Ã»ÓГÀà”ÕâÒ»¹Ø¼ü×Ö——ÔÚ´ó¶àÊýÓïÑÔÖж¼ÊÇʹÓÃclass×÷Î ......