对象的constructor属性用于返回创建该对象的函数,也就是我们常说的构造函数.下面本篇文章就来带大家认识一下JavaScript的constructor属性,希望大家如果觉得本站发布的文章不错,请转发分享给您身边的朋友,您的支持是我们最大的动力.
JavaScript constructor属性
作用:constructor属性返回对Object创建实例对象的构造函数的余如吵引用.
说明:在JavaScript中,每个具有竖侍原型的对象都会自动获得constructor属性.除了arguments、Enumerator、Error、Global、Math、RegExp、Regular Expression等一些特殊对象之外,其他所有的JavaScript内置对象都具备constructor属性.例如:Array、Boolean、Date、Function、Number、Object、String等.
语法:
object.constructor注意:constructor属性的值是对函橡蔽数本身的引用,而不是包含函数名称的字符串.
JavaScript constructor属性的使用示例
示例1:
var test=new Array();
if (test.constructor==Array)
{
document.write("这是一个数组");
}
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("这是一个字符串");
输出:
这是一个数组
function employee(name,job,born)
this.name=name;
this.job=job;
this.born=born;
console.log(bill.constructor);
以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!