1,对象的创建(三种方式)
//第一种方式 obj=new Object();//不常用,但需注意Object的O为大写
//第二种方式 //注意在对象内部声明成员属性和成员方法的规则,使用:和,号 var obj={ name:'lily', age:26, dance:function(){ alert('dance'); } }
3.
//第三种
function obj(name,age,sex){
//成员属性
this.age=age;
this.name=name;
this.sex=sex;
//成员方法
this.sing=function (){
alert('sing');
}
}
var china=new obj('lily',23,'女');
//可对china对象进行操作
2,对象成员属性的添加
obj.name='lily';
obj.age=28;
obj['sex']='女';
3,对象成员方法的添加
obj.dance=function (){
alert('i can dancing');
}
obj['sing']=function (){
alert('i can singing');
}
4,对象中属性的访问
alert(obj.name);
alert(obj['age']);
5,对象中方法的调用
obj.dance();
obj['sing']();
6,this关键词的使用
//this 当前调用的对象
obj.allFunc=function (){
this.sing();
this.dance();
}
7,成员属性删除
delete obj.name;
delete obj.age;