1 <!DOCTYPE html>
2 <html>
3
4 <head>
5 <meta charset="utf-8" />
6 <title></title>
7 </head>
8
9 <body>
10
11 </body>
12
13 <script>
14 // var user = {
15 // name: 'tom',
16 // age: 20,
17 // worke: '工人',
18 // play: function() {
19 // alert('打篮球');
20 // },
21 // habbit: ['音乐', '相声', '游戏', '电影']
22 // }
23 // alert(user.play instanceof Function)
24 // if(user.play instanceof Function) {
25 // user.play();
26 // }
27 // for(var a in user) {
28 // //alert(user[a] instanceof Function);
29 // if(user[a] instanceof Function) {
30 // user[a]();
31 // } else if(user[a] instanceof Array) {
32 // for(var i = 0; i < user[a].length; i++) {
33 // alert(user[a][i]);
34 // }
35 // } else {
36 // alert(user[a]);
37 // }
38 // }
39 //
40
41 function Student(name, age) {
42 this.name = name;
43 this.age = age;
44 this.test = function() {
45 alert(this.name);
46 alert(this);
47 }
48 }
49 var stu = new Student('tom', 20);
50 Student.s = 2222; //类属性,只有类才能访问到,对象访问不到(类方法也是这样)
51 alert(stu.s); //结果 undefined
52 alert(Student.s); //结果 2222
53 var name = 'window全局属性'; //等同于 window.name='window全局属性'
54 //this代表当前对象,但有时也要注意this的确切指向
55 alert(stu.name);
56 alert(stu.age);
57 stu.test();//this 指向stu
58 //等同于 var f=function(){alert(this.name);alert(this);} 此时的this不再是stu,而是全局对象window
59 var f = stu.test;
60 f(); //等同于 window.f() this 指向window
61 </script>
62
63 </html>