<!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>箭头函数</title>
</head>
<body>
<button id="btn">点我一下</button>
<script>
function fn1() {
return 123
}
let a = fn1();
console.log(a);
let fn2 = () => 123;
let b = fn2();
console.log(b);
let fn3 = arg => arg;
let c = fn3(123);
console.log(c);
let fn4 = (a, b) => {
let str = a + b;
return str
};
let obj = new fn5();
let a = fn6('小明', '18');
console.log(a);
document.getElementById('btn').onclick = function() {
console.log('外面的this', this)
setTimeout(function() {
console.log('里面的this', this)
}, 1000)
}
document.getElementById('btn').onclick = function() {
console.log('外面的this', this)
let that = this;
setTimeout(function() {
console.log('里面的this', that)
}, 1000)
}
document.getElementById('btn').onclick = function() {
console.log('外面的this', this)
setTimeout(() => {
console.log('里面的this', this)
}, 1000)
}
</script>
</body>
</html>