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

[Javascript]typeofº¯ÊýÓëconstructorÊôÐÔ

½ñÌìżȻ¿´µ½ÁËconstructorÕâ¸ö¶«¶«£¬²»Ã÷°×ÓÃ;¡£Õҵ㶫Î÷±¸Íü
typeofº¯ÊýµÄÓ÷¨¿ÉÄܲ»ÓÃÎÒ¶à˵£¬´ó¼Ò¶¼ÖªµÀÔõôÓ᣶øconstructorÊôÐÔ´ó¼Ò¿ÉÄܾÍÄ°Éúµã¡£ÔÚ¡¶¾«Í¨JavaScript¡·Õâ±¾ÊéÖÐÓÐÌáµ½constructµÄÓ÷¨£¬µ«ÎÒÓÃ×Ô¼ºµÄ¼¸¸öä¯ÀÀÆ÷£¨IE7.0 / Firefox1.9 / Opera9.50£©²âÊԵĽá¹ûÈ´ºÍÊéÉÏ˵µÄ²»Ò»Ñù¡£µ«ÊÇÈÔÈ»ÊÇÓа취ͨ¹ýconstructorÊôÐÔÀ´¼ì²é±äÁ¿ÀàÐ͵ġ£
ÕâÀïÏȲ¹³äһϣ¬ÎªÊ²Ã´Ã÷Ã÷ÓÐtypeofº¯Êý¿ÉÒԺܷ½±ãµØÓÃÀ´¼ì²âÀàÐÍ£¬»¹ÒªÓÃconstructorÄØ£¿
ÒòΪtypeof»á°ÑËùÓеÄÊý×éÀàÐÍÒÔ¼°Óû§×Ô¶¨ÒåÀàÐÍÅжÏΪobject£¬´Ó¶øÎÞ·¨ÖªµÀ¸üÈ·ÇеÄÐÅÏ¢¡£¶øconstructorÈ´¿ÉÒÔ½â¾öÕâ¸öÎÊÌâ¡£
ok£¬Ã÷°×ÁËÎÒÃÇΪʲôҪÓÃconstructor£¬ÏÖÔÚÈÃÎÒ´ø´ó¼ÒÒ»²½²½ÈÏʶһÏÂtypeofºÍconstructorÓ÷¨Ö®¼äµÄ²îÒì°É¡«
Ê×ÏÈÎÒÃÇÔËÐÐÒ»ÏÂÏÂÃæÕâ¶Î´úÂ룺
1 var i;
2 alert(typeof(i));
3 alert(i.constructor);
Õâ3ÐдúÂë¸æËßÄãʲôÇé¿öÏ¿ÉÒÔÓÃconstructor¡£
Äã¿ÉÒÔ¿´µ½µÚ2Ðзµ»ØÁË×Ö·û´®'undefined'£¬¶øµÚÈýÐÐÔò·¢ÉúÁË´íÎó£¬Ô­ÒòÊÇi±äÁ¿»¹Ã»ÓÐÀàÐͶ¨Ò壬×ÔȻҲûÓÐconstructorµÄ´æÔÚ¡£
´ÓÕâÒ»µãÉÏ¿´£¬typeof¿ÉÒÔ¼ì²éµ½±äÁ¿ÊÇ·ñÓж¨Ò壬¶øconstructÖ»Äܼì²éÒѶ¨Òå±äÁ¿µÄÀàÐÍ¡£
ÔÙÔËÐÐÒ»ÏÂÏÂÃæÕâ¶Î´úÂ룺
1 var i = 2;
2 alert(typeof(i));
3 alert(i.constructor);
4 alert(typeof(i.constructor));
Äã»á¿´µ½µÚ2Ðзµ»ØÁË×Ö·û´®'number’£¬µÚ3Ðзµ»ØÁËÒ»´®ÀàËƺ¯Êý¶¨ÒåµÄ´úÂë×Ö·û´®£¨Õâ¾ÍÊǸú¡¶¾«Í¨JavaScript¡·Ò»ÊéÖнéÉܵIJ»Ò»ÑùµÄµØ·½£©¡£
ÎÒÃÇÔÙÓÃtypeof¼ì²éÒ»ÏÂconstructorµ½µ×ÊǸöʲôÑùÀàÐ͵ÄÊôÐÔ£¬µÚ4Ðзµ»Ø½á¹û'function'£¬Ò²¾ÍÊÇ˵£¬Êµ¼ÊÉÏconstructorÊÇÒ»¸öº¯Êý£¬¸üÈ·ÇеØ˵ÊÇÒ»¸ö¹¹Ô캯Êý¡£ÕâʱÄã¾Í¿ÉÒÔÖªµÀ£¬ÎªÊ²Ã´constructor¿ÉÒÔ¼ì²é³ö¸÷ÖÖÀàÐÍÁË¡£
Óо­ÑéµÄ³ÌÐòÔ±¿´µ½ÕâÀïÓ¦¸ÃÖªµÀÒªÔõôÀûÓÃconstructorÀ´¼ì²é±äÁ¿ÀàÐÍÁË¡£·½·¨ÓжàÖÖ£¬ÕâÀïÌṩһÖֱȽÏÈÝÒ×Àí½âµÄ·½·¨¡£
ÆäʵÏë·¨ºÜ¼òµ¥£¬¾ÍÊÇ°Ñconstrucorת»¯Îª×Ö·û´®£¬Í¨¹ýÑ°ÕÒÆ¥Åä×Ö·û´®£¨functionÃû£©À´È·¶¨ÊÇ·ñÖ¸¶¨ÀàÐÍ¡£ÈçÏÂÀý×Ó£º
1 function user() {};
2 var i = new user();
3 alert((i.constructor+'').match(/user/) == null);
Õâ½ö½öÊǸö¼òµ¥µÄÀý×Ó¡£Èç¹û·µ»ØtrueÔò±äÁ¿i²»ÊÇuserÀàÐÍ£¬·µ»ØfalseÔò±äÁ¿ÊÇuserÀàÐÍ¡£
µ±È»£¬ÕâÑù¼ì²âÊDz»¹»¾«È·µÄ£¬±ÈÈçÆäʵËûÊÇÒ»¸ömyuserÀàÐ͵Äʱºò£¬Í¬Ñù»á±»ÈÏΪÊÇuserÀà¡£ËùÒÔÄãÐèÒªÊéд¸ü¾«È·µÄÕýÔò±í´ïʽȥ½øÐÐÆ¥Åä¡£
¿ÉÒÔÕâÑù¼


Ïà¹ØÎĵµ£º

ת javascriptʵÏÖ½Ó¿Ú

Ô­ÎĵØÖ·:http://www.cnblogs.com/harrychen66/archive/2008/10/10/488457.html
 javascriptʵÏÖ½Ó¿Ú
ÏàÐźܶàÈËÖ®ËùÒÔ¶ÔjavascriptûÓкøÐ,¿ÉÄÜÊÇÒòΪËüÌ«ËæÒâÁË,ÀýÈ綨Òå±äÁ¿¿ÉÒÔËæÒâµÄ¼Óvar,»òÕß²»¼Ó,ÿÌõÓï¾äºóÃæµÄ¿ÉÒÔËæÒâµÄ¼ÓÉÏ";",»òÕß²»¼Ó,¿ÉÄÜ×îÄÑÈÌÊܵÄÊÇ,varÁËÒ»¸ö±äÁ¿ºó,Ëü¿ÉÒÔÊÇÈκÎÀàÐÍ,û ......

JavaScriptÖеÄwindow¶ÔÏó

window¶ÔÏó£ºÃ¿Ò»¸ö¸Ã¶ÔÏó´ú±íÒ»¸öä¯ÀÀÆ÷´°¿Ú
1.³£Ó÷½·¨ÈçÏÂ
      open("Òª´ò¿ªµÄÒ³ÃæÎļþÃû","´ò¿ª´°¿ÚÔÚ²Ù×÷ϵͳÖеÄÃû³Æ(ÈκÎÃû³Æ¶¼¿ÉÒÔ)",
               "toolbar=?,menubar=?,top=?,left=?,width=?,height=?" ......

JavaScriptÖеÄDate¶ÔÏó

1.ÉùÃ÷Ò»¸öDateʱ¼ä¶ÔÏóµÄ·½Ê½ÓÐÒÔÏÂÈýÖÖ
     Date()£º±íʾ¹¹ÔìÒ»¸öµ±Ç°ÏµÍ³Ê±¼ä¶ÔÏó
     Date(int year,int month,int day)£º¹¹ÔìµÄʱ¼ä¶ÔÏóËùÖ¸ÏòµÄʱ¼äΪ Ä꣺1900+year;Ô£ºmonth+1;ÈÕ£ºday;ʱ,·Ö,Ã룺00
     Date(int millsecond)£º¹¹ÔìµÄʱ¼ä¶ÔÏó ......

JavaScriptÖг£ÓõÄʼþ

JavaScriptÖÐÓÐÒÔϳ£ÓõÄʼþ£¬ËüÃÇ¿ÉÒÔͨ¹ýJavaScriptÖеÄ×Ô¶¨Ò庯ÊýÀ´ÏìÓ¦
1.onclickʼþ
     µ¥»÷ʼþ£¬¼´Óû§µ¥»÷Êó±ê°´Å¥Ê±·¢ÉúµÄʼþ£¬¿ÉÒÔÔÚÒÔÏ»ù±¾¶ÔÏóÖвúÉú¸Ãʼþ£ºbutton,radio,checkbox,submit,reset
2.onchangeʼþ
     ¸Ä±äʼþ£¬Í¨³£·¢ÉúÔÚÒÔÏÂÁ½ÖÖÇé¿ö
& ......

JavascriptÖжÔÏóµÄ»ù±¾Ó÷¨

ÉùÃ÷£º
function person(name, country)
{
this.name = name;
this.country = country;
}
ʵÀý»¯¶ÔÏó£º
var theauthor = new person('Daniel', 'U.S.A.');
ÒýÓãº
function sayHello(objPerson)
{
return "Hello " + objPerson. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ