- var person= {
- name: 'zhangsan',
- pass: '123' ,
- 'sni.ni' : 'sss',
- hello:function (){
- for(var i=0;i<arguments.length;i++){
- //在不知參數個數情況下可通過for循環遍歷
- // arguments這個是js 默認提供
- alert("arr["+i+"]="+arguments[i]);
- }
- }
- }
- //遍歷屬性
- for(var item in person){
- if(typeof person[item] === 'string'){
- alert("person中"+item+"的值="+person[item]);
- }else if(typeof person[item] === 'function'){
- person[item](1,1);//js 的function的參數可以動態的改變
- }
- }
- //添加屬性
- person.isMe = 'kaobian'; // 這種是屬性名字正常的
- //當屬性名字不正常時,像下面這種,必須用這種形式的,
- person['isMe.kaobian'] = 'hello kaobian'; //上面的也可以用下面的形式
- for(var item in person){
- if(typeof person[item] === 'string'){
- alert("person中"+item+"的值="+person[item]);
- }else if(typeof person[item] === 'function'){
- person[item](1,1);
- }
- }