<!--******javascript function********-->
function person()
{
this.name="lage";
this.age=18;
this.weight="60kg";
this.height="175cm";
this.sex="male";
this.show=function(){
alert("姓名"+this.name+"年龄"+this.age+"性别"+this.sex+"体重"+this.weight+"身高"+this.weight);
}
};<!--******html********-->
var person=new person();
person.show();
var myperson=new person();
document.write("年龄:"+myperson.age);新手上路,问个为什么在第二处实例化person的时候,结果为什么不显示出来?
说明:链接外部js文件正常
function person()
{
this.name="lage";
this.age=18;
this.weight="60kg";
this.height="175cm";
this.sex="male";
this.show=function(){
alert("姓名"+this.name+"年龄"+this.age+"性别"+this.sex+"体重"+this.weight+"身高"+this.weight);
}
};<!--******html********-->
var person=new person();
person.show();
var myperson=new person();
document.write("年龄:"+myperson.age);新手上路,问个为什么在第二处实例化person的时候,结果为什么不显示出来?
说明:链接外部js文件正常
person.show();
改成
var person1=new person();
person1.show();
//你把实例名和类名弄成一样的,当然不行,把实例名称换一下吧
var person=new person();
person.show(); //这里的运行当然OK,因为person已经变成一个对象了
var myperson=new person(); //因为这里的person已经是一个实例,所以不能再用来实例化了
document.write("年龄:"+myperson.age); //不出来
/*楼主可以这样改一下*/
<!--******javascript function********-->
function Person() //注意:类名我们一般首字母大写
{
this.name="lage";
this.age=18;
this.weight="60kg";
this.height="175cm";
this.sex="male";
this.show=function(){
alert("姓名"+this.name+"年龄"+this.age+"性别"+this.sex+"体重"+this.weight+"身高"+this.weight);
}
};<!--******html********-->
var person=new Person(); //和你的代码比较一下
person.show();
var myperson=new Person(); //再比较一下
document.write("年龄:"+myperson.age);