<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button>按钮</button>
</body>
<script>
console.log(this);
function fun() {
console.log(this);
}
fun();
function fun() {
function sayName() {
console.log(this);
}
sayName();
}
fun();
function outerFun() {
this.name = '小小';
this.sayName = function () {
console.log(this);
}
}
let outer = new outerFun();
outer.sayName();
document.querySelector("button").onclick = function () {
console.log(this);
}
class Person {
constructor() {
console.log(this);
}
}
let person = new Person();
function Admin() {
this.sayName = function () {
console.log(this);
setTimeout(() => {
console.log(this);
}, 100)
}
}
var admin = new Admin();
admin.sayName();
function Admin() {
this.sayName = function () {
console.log(this);
setTimeout(function () {
console.log(this);
}, 100)
}
}
var admin = new Admin();
admin.sayName();
</script>
</html>
结果
