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/
Ïà¹ØÎĵµ£º
Òý×Ó
±à³ÌÊÀ½çÀïÖ»´æÔÚÁ½ÖÖ»ù±¾ÔªËØ£¬Ò»¸öÊÇÊý¾Ý£¬Ò»¸öÊÇ´úÂë¡£±à³ÌÊÀ½ç¾ÍÊÇÔÚÊý¾ÝºÍ´úÂëǧ˿ÍòÂƵľÀ²øÖгÊÏÖ³öÎÞÏÞµÄÉú»úºÍ»îÁ¦¡£
Êý¾ÝÌìÉú¾ÍÊÇÎľ²µÄ£¬×ÜÏë±£³Ö×Ô¼º¹ÌÓеı¾É«£»¶ø´úÂëÈ´ÌìÉú»îÆã¬×ÜÏë¸Ä±äÕâ¸öÊÀ½ç¡£
Äã¿´£¬Êý¾Ý´úÂë¼äµÄ¹ØϵÓëÎïÖÊÄÜÁ¿¼äµÄ¹Ø ......
function addLoadEvent(fun) {
var oldonload = window.onload;
if(typeof(window.onload) != 'function') {
window.onload = fun;
} else {
window.onload = function() {
oldonload();
fun();
}
}
}
//function insertAfter(newElement, targentElement)
function insertAfter(insertedNode, ......
Ò»¡¢½éÉÜÓëFlash¶¯»¿ØÖÆÓйصÄjavascriptº¯Êý£º
º¯ÊýÃû ʹÓà &n ......
Ò»¡£È¡±í¸ñ¶ÔÏó
var getTable= document.getElementById("tabHeTong");
¶þ¡£²åÈëÐÐ
var oTR = getTable.insertRow();//ÐÂÔöÒ»ÐÐ
Èý¡£Ä³ÐмÓÈëÁÐ
var oTDa = oTR.insertCell();//ÐÂÔöÒ»ÁÐ
var oTDb = oTR.insertCell();//ÐÂÔö¶þÁÐ
var oTDc = oTR.insertCell();//ÐÂÔöÈýÁÐ
ËÄ¡£É¾³ýÐУº
getTable. ......
¡¶Îò͸JavaScript¡·Ñ§Ï°±Ê¼Ç
ÔÎĵØÖ·£ºhttp://www.cnblogs.com/leadzen/archive/2008/02/25/1073404.html
ÕâÊÇÒ»±¾ºÜÐÎÏóÉú¶¯µÄÊ飬ʹÎÒÃÇ¿ÉÒÔ¸üÉîµØÁ˽âÁËJavaScript¡£
ÒýÑÔ
±à³ÌÊÀ½çÀïÖ»´æÔÚÁ½ÖÖ»ù±¾ÔªËØ£¬Ò»¸öÊÇÊý¾Ý£¬Ò»¸öÊÇ´úÂë¡£±à³ÌÊÀ½ç¾ÍÊÇÔÚÊý¾ÝºÍ´úÂëǧ˿ÍòÂƵ ......