1
2
3
4
5
6
7
| var phone = {
price:'5000$',
weight:'150g',
chat:function(){
alert('can chat');
}
}
|
1
2
3
4
5
6
7
8
9
10
11
| funtion fruit(p,c,w){
this.price = p;
this.color = c;
this.weight = w;
this.eat = function(){
alert('can eat');
}
}
var apple = new fruit('5$','red','50g');
alert(apple.color);
|
1
2
3
4
5
6
7
8
9
| var phone = {
price:'5000$',
weight:'150g',
chat:function(){
alert('can chat');
}
}
document.write(phone.price);
document.write(phone['price']);
|
1
2
3
4
5
| for(x in y){
}
//x是属性名或方法名
//y是要遍历的对象名
|
1
2
3
4
5
6
| //phone为一个对象
delete phone.price; //删除对象属性
phone = null; //销毁对象
|