js对象问题
<script>functionperson(firstname,lastname,age,eyecolor){this.firstname=firstname;this...
<script>
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
this.changeName=changeName;
function changeName(name)
{
this.lastname = name;
}
}
myPerson = new person("sy","w","25","black");
document.write(myPerson.lastname);
myPerson.changeName("s");
document.write(myPerson.lastname);
</script>
这句有啥用:
this.changeName=changeName;
这句去掉之后最后一句document.write(myPerson.lastname);输出没结果。谢谢 展开
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
this.changeName=changeName;
function changeName(name)
{
this.lastname = name;
}
}
myPerson = new person("sy","w","25","black");
document.write(myPerson.lastname);
myPerson.changeName("s");
document.write(myPerson.lastname);
</script>
这句有啥用:
this.changeName=changeName;
这句去掉之后最后一句document.write(myPerson.lastname);输出没结果。谢谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询