JavaScript constructorÊôÐÔ
Definition and Usage
¶¨ÒåÓëÓ÷¨The constructor property is a reference to the function that created an object.
constructorÊôÐÔÊÇËù½¨Á¢¶ÔÏóµÄº¯Êý²Î¿¼Syntax
Óï·¨object.constructor
Example 1
¾ÙÀý
In this example we will show how to use the constructor property:
ÔÚÕâ¸ö¾ÙÀýÖÐÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓÃconstructorÊôÐÔ£º
<script type="text/javascript">
var test=new Array()
if (test.constructor==Array)
{document.write("This is an Array")}
if (test.constructor==Boolean)
{document.write("This is a Boolean")}
if (test.constructor==Date)
{document.write("This is a Date")}
if (test.constructor==String)
{document.write("This is a String")}
</script>
The output of the code above will be:
Êä³ö½á¹ûΪ£º
This is an Array
Example 2
¾ÙÀý2
In this example we will show how to use the constructor property:
ÔÚÕâ¸ö¾ÙÀýÖÐÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓÃconstructorÊôÐÔ£º
<script type="text/javascript">
function employee(name,jobtitle,born)
{
this.name=name
this.jobtitle=jobtitle
this.born=born
}
var fred=new employee("Fred Flintstone","Caveman",1970)
document.write(fred.constructor)
</script>
The output of the code above will be:
Êä³ö½á¹ûΪ£º
function employee(name, jobtitle, born)
{this.name = name; this.jobtitle = jobtitle; this.born = born;}
Try-It-Yourself Demos
³¢ÊÔÓëÑÝʾ
constructor - example 1
In this example we will show how to use the constructor property.
ÔÚÕâ¸ö¾ÙÀýÖÐÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓÃconstructorÊôÐÔ
constructor - example 2
In this example we will show how to use the constructor property.
ÔÚÕâ¸ö¾ÙÀýÖÐÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓÃconstructorÊôÐÔ
http://www.w3pop.com/learn/view/doc/jsref_constructor_array/
Ïà¹ØÎĵµ£º
Òý×Ó
±à³ÌÊÀ½çÀïÖ»´æÔÚÁ½ÖÖ»ù±¾ÔªËØ£¬Ò»¸öÊÇÊý¾Ý£¬Ò»¸öÊÇ´úÂë¡£±à³ÌÊÀ½ç¾ÍÊÇÔÚÊý¾ÝºÍ´úÂëǧ˿ÍòÂƵľÀ²øÖгÊÏÖ³öÎÞÏÞµÄÉú»úºÍ»îÁ¦¡£
Êý¾ÝÌìÉú¾ÍÊÇÎľ²µÄ£¬×ÜÏë±£³Ö×Ô¼º¹ÌÓеı¾É«£»¶ø´úÂëÈ´ÌìÉú»îÆã¬×ÜÏë¸Ä±äÕâ¸öÊÀ½ç¡£
Äã¿´£¬Êý¾Ý´úÂë¼äµÄ¹ØϵÓëÎïÖÊÄÜÁ¿¼äµÄ¹Ø ......
ÔÚ¿ª·¢Ò»¸ö½É·Ñ½»Ò×ʱ£¬ÏÈ·¢ËͲéѯÇëÇóµ½ÏµÍ³A£¬ÏµÍ³A·µ»ØÒ»¸ö×Ö·û´®¸ñʽµÄÇ··Ñ½ð¶î£¬ÒòΪÊǶ¨³¤µÄ£¬ËùÒÔ¶¼ÊÇÇ°²¹0£¬±¾À´ÐèÒªÏÈ×ö´¦ÀíµÄ£¬µ«ÊÇÓÉÓÚ²éѯ½á¹ûÈç¹ûÊÇÇ··ÑµÄ£¬¿Í»§·¢Æð½É·Ñ½»Ò×ʱ£¬»áË͸øϵͳBµÄ¸ñʽ£¬ÓëϵͳA·µ»ØµÄÊÇÒ»ÑùµÄ£¬Òò´Ë¾ÍÔÑù±£´æÈ»ºóÉÏËÍ£¬¿ÉÊÇÔÚϵͳ²âÊÔʱ£¬È´·¢ÏÖÁËÒ»¸öÆæ¹ÖµÄÏÖÏó£¬ÏµÍ³A·µ»ØµÄ²é ......
1. oncontextmenu="window.event.returnValue=false" ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectstart="return false"> È¡ÏûÑ¡È¡¡¢·ÀÖ¹¸´ÖÆ
3. onpaste="return false" ²»×¼Õ³Ìù
4. oncopy="return false;" oncut="return f ......
ÔÚjavascriptº¯ÊýÌåÄÚ£¬±êʶ·ûarguments¾ßÓÐÌØÊ⺬Òå¡£ËüÊǵ÷ÓöÔÏóµÄÒ»¸öÌØÊâÊôÐÔ£¬ÓÃÀ´ÒýÓÃArguments¶ÔÏó¡£Arugments¶ÔÏó¾ÍÏñÊý×飬עÒâÕâÀïÖ»ÊÇÏñ²¢²»Êǹþ¡£
javascriptº¯ÊýÌåÄÚ£¬argumentsÏñÊý×é(²¢²»ÊÇÕæµÄÊý×飬ÊÇÒ»¸öArguments¶ÔÏó£¬ÔÙ´ÎÇ¿µ÷)Ò»Ñù£¬ÓÐlengthÊôÐÔ£¬¿ÉÒÔ´ú±í´«¸øº¯ÊýµÄ²ÎÊýµÄ¸öÊý¡£
ÒýÓÃÒ»¸öÐÎʽ² ......