javascript自定义对象
<script type="text/javascript"> var temp = new Object(); temp.name = "涵"; temp.age = 18; temp.print = function (){ alert("姓名"+ this.name + "年龄" + this.age); } temp.print(); </script>
var temp = { name:"涵", age:18, print:function (){ alert("姓名->"+this.name+"年龄—>"+this.age) } } temp.print();
注意:在使用花括号时,在每一个属性之间要用逗号隔开,而在位属性赋值的时候,要用:(分号)