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/
相关文档:
在上传操作中,经常会遇到要求指定上传文件的格式,下面的实例是在客户端通过JavaScript验证上传图片格式为jpg/gif/png
<html>
<head>
<mce:script language="JavaScript" type="text/JavaScript"><!--
var img=null;
function checkPic(picForm){
var location=picForm.pic.v ......
示例:
- - - - - - - - - - - -
<body>
<input type="button" value="create" onclick="createTr();">
<table border='1' id="t" >
</table>
<input type="button" value="提交" onclick="okss();" />
</body>
<script type="text/javascript">
&nbs ......
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 ......
一、介绍与Flash动画控制有关的javascript函数:
函数名 使用 &n ......
求 555.555的四舍五入保留两位小数
使用Math.round 怎么都算不对,结果都是555.55 ,貌似是因为java计算浮点数时会莫名其妙在结尾跟上一串数字 比如555.55500000003
无奈只能写这个方法
function round(a,b){
var s=a.toString().indexOf(".");
a0=a.toString().substr(0,s+b+1);
a1=Math.round(a.toString().sub ......