javascritpt创建对象

javascript添加对象示例:

<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.");
</script>

结果:

Bill is 56 years old.

 替代语法,结果相同:

<script>
person={firstname:"Bill",lastname:"gates",age:56,eyecolor:"blue"}

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

 

posted @ 2018-01-08 15:45  万里冰封  阅读(164)  评论(0编辑  收藏  举报