回顾数组Api
<body>
<!--
数组循环
函数默认返回 undefined
-->
<script>
let arr = ["iu","lisa","夏栀","锦鲤","丫丫"];
let newArr = arr.forEach((item,index,arr)=>{
// console.log(item,index,arr);
})
let newArr1 = arr.map((item,index,arr)=>{
// console.log(item,index,arr);
return item + "大哥"
})
// reduce(函数,number) 返回值 计算的结果
//index next值对应的下标
//arr 数组本身
//next 当前值
//prev 循环上一次计算的结果,通过return返回的数; 传递第二个参数,prev第一次数据就是传入的数据
// 没有传递对应参数,prev第一次数据就是数组的第一项数据
let arr1 = [11,22,3,4,5,6];
let newArr2 = arr1.reduce((prev,next,index,arr)=>{
return prev + next
})
</script>
</body>
定时器
<!-- 定时器 只执行一次
setTimeout(函数,date)设置多少之后执行对应的代码;返回值是一个序号
参数 function || ()=>{}
date 设置多少毫秒之后执行,参数函数
间隔定时器
setInterval(函数,date)
参数
函数 function || ()=>{}
date 设置多少毫秒之后执行,参数函数
clearInterval(序号)取消间隔定时器
clearInterval(序号)取消定时器
动画帧 执行频率,根据你屏幕刷新次数来定时的
let time =requestAnimationFrame(函数名);返回一个序号
function add(){
对应代码
requestAnimationFrame(add)
}
add()|| requestAnimationFame(add)
cancelAnimationFrame(time) 清除动画帧执行
-->
定时器异步代码和同步代码相关代码段
<script>
//定时炸弹 ?
// let time =setTimeout(()=>
// {
// console.log("biubiubiu,bombombom");
// },5)
// console.log(time,"time");
//红绿灯 每隔多少秒量红灯,
// let time1 =setInterval(()=>{
// console.log("红灯");
// },1000)
// console.log(time1,"time1");
// let index = 0;
// let time;
// function add1(){
// time =requestAnimationFrame(add1)
// //操作bug
// // index++
// // if(index =100){
// // cancelAnimationFrame(time)
// // }
// console.log(111);
// }
// requestAnimationFrame(add1)
let a=10;
setTimeout(()=>{
console.log(a);
},0)
console.log("大哥");
function add(a){ //隐士创建一个变量
console.log(a);// a undefined
a=100
}
add()
// 从上往下执行; 所有的同步代码先执行完毕,异步代码才会执行,
// 异步代码;定时器 动画帧requestAnimationFrame()启动才是异步
</script>
this
<body>
<!--
函数才有的this => this 代表着谁 => 函数this默认是window
1.函数this默认是window
2.对象.调用函数名()=> 该函数里面的this代表 调用这个函数的对象
3.箭头函数本身没有this
-->
</body>
<script>
let ss=10;
function add(){
console.log(this);
}
add()
let aa=function(params){
console.log(this);
}
aa()
//es6写法
let obj={
name:"123",
qwe(){
console.log(this,"obj的qwe函数");
}
}
</script>
Math
<!--
math 数学对象
1.Math.random() 随机数0-1
2.Math.ceil(字符) 向上取整
参数
字符串 任意类型
3. Math.floor(字符) 向下取整
参数
字符串 任意类型
4.Math.round(字符) 四舍五入
参数
字符串 任意类型
5.Math.min(一批字符串) 取其中的最小值 Math.max(一批字符串)取其中的最大值
6.Math.PI π
7.Math.pow(底数,次幂) 简写 2**2次幂
8.~~number 只要整数
其它类型都会转化成Number
-->
<script>
// 随机数
// let ss=Number.parseInt(Math.random() *100)
// console.log(ss);
//向上取整
// let a=Math.random()*100
// console.log(Math.ceil(a));
//向下取整
// let a1=Math.floor("23.4")
// console.log(a1);
// 四舍五入
// let a2=Math.round(10/3)
// console.log(a2);
// //取最小值
let ass =[1,2,3,4]
console.log(Math.min(...ass));
// console.log(Math.min(12,2,3,45,6));
// console.log(Math.max(12,2,3,45,6));
//函数形参里面 ...q 写在形参最后一个,接收所有剩余的实参
//扩展...[] 将里面的每一项单独拿出来
</script>
(Math三角函数)
<!--
js 中的Math 对象三角函数,不能直接传递角度值 传递弧度值
角度*Marh.PI/180
Math.sin(30*Math.PI/180)
Math.cos()
Math.tan()
sin30=1/2
对边是斜边的一半
-->