[¶î£]javascriptÖеÄÊý¾ÝÀàÐÍ¡¢ObjectÓëFunction
1. Êý¾ÝÀàÐÍ
javascriptÖаüº¬6ÖÖÊý¾ÝÀàÐÍ£ºundefined¡¢null¡¢string¡¢number¡¢booleanºÍobject¡£ÆäÖУ¬Ç°5
ÖÖÊÇÔʼÊý¾ÝÀàÐÍ£¬objectÊǶÔÏóÀàÐÍ¡£
objectÀàÐÍÖаüÀ¨Object¡¢Function¡¢String¡¢Number¡¢Boolean¡¢Array¡¢Regexp¡¢Date¡¢
Globel¡¢Math¡¢Error£¬ÒÔ¼°ËÞÖ÷»·¾³ÌṩµÄobjectÀàÐÍ¡£
2. ÀàÐÍÅжÏ
ͨ³£ÔÚjavascriptÖнøÐÐÀàÐÍÅжÏÖ÷Ҫͨ¹ý3ÖÖ·½Ê½£ºtypeof¡¢instanceof¡¢constructor¡£
2.1 typeof
typeof²Ù×÷¿ÉÄÜ·µ»ØµÄÀàÐÍΪundefined¡¢object¡¢number¡¢string¡¢function¡¢boolean¡£µ«ÊÇ»áÓÐÒ»
ЩÇé¿ö²¢²»ÄÜÍêÈ«ÅжÏ׼ȷ¡£±ÈÈçtypeof new String('')µÄֵΪobject¡£
2.2 constructor
ÓÐʱºòÎÒÃÇ¿ÉÄÜ»áºÜ͵ÀÁµÄʹÓÃa.constructor ==
String½øÐÐÀàÐÍÅжϣ¬µ«ÊÇconstructorÆäʵÊDz»¿¿Æ׵Ķ«Î÷¡£ÒòΪµ±ÎÒÃǵ÷ÓÃa.constructorµÄʱºò£¬ÄÚ²¿²Ù×÷ÆäʵÊÇ
ToObject(a).prototype.constructor£¨ToObjectÊÇʲô£¬¿´ÏÂÎķֽ⣩¡£
¿´ÏÂÃæÒ»¶Î´úÂë¾ÍÄÜÃ÷°×£º
String
.
prototype
.
constructor
=
Number
;
alert
(
'test'
.
constructor
==
String
);
//Result£ºfalse
»òÕß
function
MyClass
()
{
}
MyClass
.
prototype
=
{};
alert
((
new
MyClass
).
constructor
==
MyClass
);
//Result£ºfalse
¶øÇÒ£¬Í¨¹ýconstructor²¢²»ÄÜÅжϳö¶ÔÏóʵÀýÀàÐ͵ļ̳йØϵ¡£ÒòΪjavascriptµÄ¼Ì³ÐÆäʵÊÇͨ¹ýÔÐÍÁ´ÊµÏֵģ¨ÔÐÍÁ´ÊÇʲô£¬¿´
ÏÂÎķֽ⣩¡£
ÁíÍ⣬null.constructor»áÅ׳öÔËÐÐʱµÄTypeError£¬ËùÒÔʹÓÃconstructor³ýÁ˲»¿¿Æ×Í⣬»¹¿ÉÄÜ°éËæ×ÅÒì³£µÄ·ç
ÏÕ¡£
2.3 instanceof
Àý×Ó£ºa instanceof String
¹ØÓÚobjectÀàÐ͵ÄÅжϣ¬Ê¹ÓÃinstanceofÅжÏÊDZȽϿ¿Æ׵ķ½·¨¡£instanceofËù×öµÄÊÂÇéÊÇ£¬ÏÈÈ¡³öÀàÐͶÔÏó(String)
µÄprototype³ÉÔ±(String.prototype)£¬È»ºóºÍÒªÅжÏÀàÐ͵ĶÔÏó(a)µÄÔÐÍÁ´ÖеĶÔÏóÖð¸ö±È½Ï¡£µ±·¢ÏÖÊÇÒ»¸ö¶ÔÏóµÄʱºò·µ»Ø
true£¬ÔÐÍÁ´Öе±Ç°½ÚµãÊÇnullµÄʱºò·µ»Øfalse¡£
ÀàÐÍÅжÏʾÀý£ºÅжÏÒ»¸ö±äÁ¿ÊÇ·ñÊÇ×Ö·û´®ÀàÐÍ
function
isString
(
str
)
{
return
(
typeof
str
==
'string'
||
str
instanceof
String
);
}
3. ÀàÐÍת»»
ecma262ÖÐÃèÊöÁËÒÔϼ¸ÖÖÀàÐÍת»»µÄ²Ù×÷£º£¨»¹ÓÐÆäËûµÄ±ÈÈçToInt32µÈ£¬ÕâÀï¾Í²»ÁÐÁË£©
ToNumber£º×ª»»³ÉnumberÐÍ
ToString£º×ª»»³ÉstringÐÍ
Ïà¹ØÎĵµ£º
Èç¹ûÄãÏë¼ÓÎÒΪºÃÓÑ£ºÇëµã»÷ÒÔÏÂÁ´½Óhttp://hi.csdn.net/invite.php?u=8943&c=759c7fc189ea23c1
µÚ1ÕÂ
¾«»ª
JavaScript
µÄÌØÐÔÖÐÓÐÒ»²¿
·ÖÌØÐÔ´øÀ´µÄÂé·³Ô¶Ô¶³¬³öËüÃǵļÛÖµ¡£ÆäÖУ¬Ò»Ð©ÌØÐÔÊÇÒòΪ¹æ·¶ºÜ²»ÍêÉÆ£¬´Ó¶ø¿ÉÄܵ¼Ö¿ÉÒÆÖ²ÐÔµÄÎÊÌ⣻һЩÌØÐԻᵼÖÂÉú³ÉÄÑÒÔÀí½âºÍÐ޸ĵĴúÂ룻һЩÌØ
ÐÔ´ ......
µÚ5ÕÂ
¼Ì³Ð
ÔÚÄÇЩ»ùÓÚÀàµÄÓïÑÔ£¨±ÈÈç
Java
£©ÖУ¬¼Ì³Ð£¨
inheritance
»ò
extends
£©ÌṩÁËÁ½¸öÓÐÓõķþÎñ¡£Ê×ÏÈ£¬ËüÊÇ´úÂëÖØÓõÄÒ»ÖÖÐÎʽ¡£Èç¹ûÒ»¸öеÄÀàÓëÒ»¸öÒÑ´æÔÚµÄÀà´ó²¿·ÖÏà
ËÆ£¬ÄÇôÄãÖ»Ðë¾ßÌå˵Ã÷Æ䲻ͬµã¼´¿É¡£Àà¼Ì³ÐµÄÁíÒ»¸öºÃ´¦ÊÇËü°üÀ¨ÁËÒ»Ì×ÀàÐÍϵͳµÄ¹æ·¶¡£ÓÉÓÚ³ÌÐòÔ±ÎÞÐë±àдÏÔʽÀàÐÍת ......
µÚ7ÕÂ
ÕýÔò±í´ïʽ
JavaScript
µÄÐí¶àÌØÐÔ¶¼½è
¼ø×ÔÆäËûÓïÑÔ¡£Óï·¨½è¼ø×Ô
Java
£¬º¯Êý½è¼ø×Ô
Scheme
£¬ÔÐͼ̳нè¼ø×Ô
Self
¡£¶ø
JavaScript
µÄÕýÔò±í´ïʽÌØÐÔÔò½è¼ø×Ô
Perl
¡£
ÕýÔò±í´ïʽÆðÔ´ÓÚ¶ÔÐÎʽÓïÑÔµÄÊý
ѧÑо¿¡£
ÔÚ
JavaScript
ÖУ¬ÕýÔò±í´ïʽµÄÓï·¨ÊǶÔ
Perl
°æµÄ¸Ä½øºÍ·¢Õ¹£¬Ëü·Ç³£ ......
http://blog.csdn.net/mouyong/archive/2010/03/10/5364047.aspx
µÚ9Õ ´úÂë·ç¸ñ
¼ÆËã»ú³ÌÐòÊÇÈËÀàÖÆÔì³öÀ´µÄ×ÔÓµÄÊÂÎï¡£³ÌÐòͨ³£Óɺܶಿ·Ö×é³É£¬±íÏÖΪº¯Êý¡¢Óï¾äºÍ±í´ïʽ£¬ËüÃDZØÐë׼ȷÎÞÎóµØ°´ÕÕ˳ÐòÅÅÁС£×îÖյĽá¹û¼¸ºõ¶¼ºÍʵÏÖËüµÄ³ÌÐòûÓÐʲôÏàËÆÖ®´¦¡£ÔÚÈí¼þµÄ²úÆ·ÉúÃüÖÜÆÚÖУ¬Í¨³£ËüÃǶ¼»á±»ÐÞ¸ ......