mirror of
https://gitee.com/many2many/java-web.git
synced 2025-01-11 14:40:55 +08:00
34 lines
819 B
HTML
34 lines
819 B
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>Title</title>
|
||
|
<script>
|
||
|
function Timer(){
|
||
|
this.s1 = 0;
|
||
|
this.s2 = 0;
|
||
|
// 箭头函数
|
||
|
setInterval(() => {
|
||
|
this.s1++;
|
||
|
console.log("****", this);
|
||
|
}, 1000);
|
||
|
// 普通函数
|
||
|
setInterval(function (){
|
||
|
console.log("####", this);
|
||
|
console.log("####", this.s2);
|
||
|
this.s2++;
|
||
|
console.log("####", this.s2);
|
||
|
}, 1000);
|
||
|
}
|
||
|
|
||
|
var timer = new Timer();
|
||
|
|
||
|
setTimeout(() => console.log('s1: ', timer.s1),3200); //s1: 3
|
||
|
setTimeout(() => console.log('s2: ', timer.s2),3200); //s2: 0
|
||
|
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
hi!!
|
||
|
</body>
|
||
|
</html>
|