日期:2014-05-16  浏览次数:20380 次

一些基本的概念理解,谁能帮我看看,我错在哪里?
<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);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
</script>

首先定义了一个函数employee 函数有name job born属性
然后创业一个对象bill
new employee("Bill Gates","Engineer",1985);是构造函数, 为了创建一个bill对象。

然后:employee.prototype.salary=null;
添加一个employee的新属性。 
到此,不明白的是为什么把employee.prototype.salary复制为null;


--------------------------------------------------------------------
第二个 :constructor 属性返回对创建此对象的 Boolean 函数的引用。
<script type="text/javascript">
var test=new Boolean();
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>
这个test是对象。new Boolean() 是创建test对象的构造函数
为什么test.constructor==Boolean 呢?  
不是:返回对创建此对象的 Boolean 函数的引用 返回的应该是函数啊。怎么直接等于Boolean

------解决方案--------------------
探讨
到此,不明白的是为什么把employee.prototype.salary复制为null;