JavaScript constructor 属性
定义和用法
constructor 属性返回对创建此对象的数组函数的引用。
语法
object.constructor
实例
例子 1
在本例中,我们将展示如何使用 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>
输出:
This is an Array
例子 2
在本例中,我们将展示如何使用 constructor 属性:
<script type="text/javascript"> function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
} var bill=new employee("Bill Gates","Engineer",1985); document.write(bill.constructor
); </script>
输出:
function employee(name, jobtitle, born)
{this.name = name; this.jobtitle = job; this.born = born;}
TIY
- constructor
- 在本例中,我们将展示如何使用 constructor 属性。
随机推荐
- sql Mirroring
http://www.codeproject.com/Articles/109236/Mirroring-a-SQL-Server-Database-is-not-as-hard-as http:// ...
- 用MSBuild和Jenkins搭建持续集成环境 - 转
http://www.infoq.com/cn/articles/MSBuild-1 http://www.infoq.com/cn/articles/MSBuild-2 MSBuild是在.NET ...
- Virtualbox虚拟机设置不完全笔记
先说说我想实现的东西,我想在虚拟机安装各种开发环境,我个人在学习Node.然后我装了一个Ubuntu Server,所以我又想共享一个windows下的文件夹,这样可以让我在windows下开发,在L ...
- 2565: 最长双回文串 - BZOJ
Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为“abc”,逆序为“cba”,不相同). 输入长度为n的串S,求S的最长双回文子串T ...
- linux下mysql的root密码忘记解决方
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- 关于asp.net mvc4 在IE8下 导出excel失败的解决办法
在使用FileResult向浏览器输出文件时(pdf,excel等),通常这样做: byte[] fileContents = Encoding.UTF8.GetBytes(sbHtml.ToStri ...
- linux源代码阅读笔记 find_entry分析
78 static struct buffer_head * find_entry(struct m_inode * dir, 79 const char * name, int namelen, s ...
- JsRender系列demo-10
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...
- POJ2418Hardwood Species
题意 : 输入若干个树木品种,里边有的是重复的,让你统计每个品种占输入的总数量的百分比,最后按字典序输出 思路 : 本题数量很大,所以采用直接统计的方式会超时,而采用的方法可以用二叉搜索树,或者用ma ...
- hdu 4418 Time travel 概率DP
高斯消元求期望!! 将n时间点构成2*(n-1)的环,每一点的期望值为dp[i]=dp[i+1]*p1+dp[i+2]*p2+……+dp[i+m]*pm+1. 这样就可以多个方程,利用高斯消元求解. ...