<html>
<body>
<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.toSource());
</script>
</body>
</html>
<html>
<body>
<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.toSource());
</script>
</body>
</html>
this.name=name;
JavaScript中没有this
你用IE浏览下看看就知道了,就是你自己写的那个类没有toSource这个方法.很明显的.
<html> <body>
<script type="text/javascript">
function employee(name, job, born) { this.name = name; this.job = job; this.born = born; this.toSource = function () { return this.name + ' ' + this.job + ' ' + this.born.toString() }; }
var bill = new employee("Bill Gates", "Engineer", 1985);
document.write(bill.toSource());
</script>
</body> </html>
或者
<html> <body>
<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.toString());
</script>
</body> </html> 我的QQ 758769729,有兴趣了共同探讨