<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自定义浏览器对象</title>
</head>
<body>
<script type="text/javascript">
var o={
name:'zs',
age:18,
sex:true,
sayHi:function(){
console.log(this.name);
}
};
/*调用*/
console.log(o.name+":"+o.age+":"+o.sex);
o.sayHi();
/**
* javascript类定义
*/
function Person(){
this.name='zs',
this.age=18,
this.sex=true,
this.sayHi=function(){
console.log(this.name);
}
}
var p=new Person();
console.log(p.name+":"+p.age+":"+p.sex);
p.sayHi();
Person.prototype.code=222;//通过类的原型添加属性
var p1=new Person();
console.log(p1.code)
//遍历属性
for(var tt in p1){
console.log(tt);
console.log(p[tt]);
}
</script>
</body>
</html>
