1<head>
2 <meta charset="UTF-8" />
3 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
4 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
5 <title>Document</title>
6 <script>
7 let obj = {
8 usr: '李四',
9 test: () => {
10 console.log(this.usr);
11 },
12 test2() {
13 console.log(this.usr);
14 },
15 };
16
17 obj.test(); //undefined
18 obj.test2();
19 </script>
20</head>
21
22<body>
23 <button>测试</button>
24 <script>
25 let btn = document.getElementsByTagName('button')[0];
26 // btn.addEventListener('click', function() {
27 // console.log(this);
28 // });
29
30 btn.addEventListener('click', () => {
31 console.log(this);
32 });
33 </script>
34</body>