对象

 1 <html>
 2   <!--声明式:不能显示-->
 3   <head>
 4   <!--设置网页编码-->
 5   <meta charset="utf-8"/>
 6    <title> 我的标题 html</title>
 7   </head>
 8   <!--能够显示的内容-->
 9   <body>
10   <script>
11      function print(s){
12          document.write(s);
13      }
14      function println(s){
15          print(s+"</br>");
16      }
17     var o=new Object();
18     o.name="Jeff";
19     o.age=23;
20     o.salary=300000;
21     for(var x in o){
22        println(x+"="+o[x]);
23     }
24     function Rect(w,h){
25         this.width=w;
26         this.height=h;
27         this.area=function(){
28             return this.width*this.height;
29         }
30     }
31     var r=new Rect(5,10);
32     println(r.area());
33     r.width=10;
34     println(r.area());
35     function Person(name,age,job){
36         this.name=name;
37         this.age=age;
38         this.job=job;
39         this.friends=["jeff","jane"];
40     }
41     Person.prototype={
42         constructor:Person,
43         sayName:function(){
44             alert(this.name);
45         }
46     };
47     var person1=new Person("jeff",23,"software Engineer");
48     var person2=new Person("Bob",24,"Doctor");
49     person1.friends.push("Van");
50     alert(person1.friends);
51     alert(person2.friends);
52     alert(person1.friends===person2.friends);
53     alert(person1.sayName===person2.sayName);
54   </script>  
55   </body>
56  </html>

 

posted @ 2021-01-18 19:00  丁帅帅dss  阅读(67)  评论(0)    收藏  举报