标签:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Object</title> 6 <script> 7 8 9 // Object 10 var obj = new Object(); 11 var obj = {} ; 12 obj.name= "小晖"; 13 obj.age = 23; 14 obj.sex = "男"; 15 obj.say = function(){ 16 alert("hello wold!"); 17 } 18 19 //delete 用于删除对象的属性 20 21 delete obj.age; 22 delete obj.name; 23 delete obj.say; 24 25 26 alert(obj.age); 27 alert(obj.name); 28 alert(obj.sex); 29 obj.say(); 30 31 32 33 //对象枚举 for in 语句式 34 for ( var aaa in obj){ 35 alert(obj[aaa]); 36 } 37 38 for ( var abc in obj ){ 39 alert(abc + " : " +obj[abc]); 40 } 41 42 //保存着用于创建当前对象的函数 43 alert(obj.constructor); 44 45 var arr = []; 46 47 alert(arr.constructor); 48 //检测给定的属性在当前的对象实例中是否存在 49 alert(obj.hasOwnProperty("name"));//true 50 51 52 53 </script> 54 </head> 55 <body> 56 57 </body> 58 </html>
标签:
原文地址:http://www.cnblogs.com/lch323/p/4519177.html