js定义对象的2中方法及示例

<!DOCTYPE html>
<html>
<body>

<script>
 
//两种定义对象的方法
//方法一
person=new Object();
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
person.eyecolor="blue";

document.write(person.firstname + " is " + person.age + " years old."+"<br/>");

/*方法二*/
function persond(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}

myFather=new persond("Bill","Gates",56,"blue");

document.write(myFather.firstname + " is " + myFather.age + " years old.");
 
</script>

</body>
</html>

 

posted @ 2016-04-08 15:26  心雨星空  阅读(199)  评论(0编辑  收藏  举报