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);输出没结果。谢谢 展开
展开全部
this.changeName=changeName; 前面的changeName可以认为是一个函数中的属性,后面的changeName则是一个函数,则执行时可以
var obj = new person(x,"A",x,x);
var obj2=new obj.changeName("B");
document.write(obj.lastname);等于A,document.write(obj2.lastname);等于B,未测,但思路是这样
var obj = new person(x,"A",x,x);
var obj2=new obj.changeName("B");
document.write(obj.lastname);等于A,document.write(obj2.lastname);等于B,未测,但思路是这样
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询