一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var i = 1;
//开启定时器,每隔0.5秒输出一次i,并且让i每次自加
//执行到定时器行时会自动开启,第一次执行为设置的间隔而不是立即执行
//以毫秒为单位,1000毫秒等于1秒
var timer = window.setInterval(function(){
console.log(i++);
},500);
//清除定时器需将其存到变量中
window.clearInterval(timer);
</script>
</body>
</html>
二
var dsq = setTimeout(function(){
console.log("3秒后输出该文字");
},3000);
clearTimeout(dsq);
var sss = "wwwww"
var user = {
sss: "ddddddddd",
getName:function(){
var d = this;
setTimeout(function(){
//wwwww
console.log(this.sss);
console.log(d.sss);
//ddddddddd
},1000)
}
}
user.getName();