摘要: 剩余参数 用于声明不确定参数数量的函数 function sum (first, ...args) { console.log(first); // 10 console.log(args); // [20, 30] } sum(10, 20, 30) 箭头函数也可以用 const sum = (. 阅读全文
posted @ 2023-07-06 18:39 luytest 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 箭头函数的作用: 1. 比function这种写法更加简洁; 2. 可以解决this指向的问题,因为它不会创建自己的this,而是继承上一级作用域的this。 使用场景: 1. 当函数内部不需要用到this的时候,都可以用箭头函数代替function; 2.需要this,但是需要的是上一级作用域的t 阅读全文
posted @ 2023-07-06 18:33 luytest 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 分为数组解构和对象解构 数组解构 $(function () { let arr = [1, 2, 3]; let [a, b, c, d] = arr; alert(a); alert(b); alert(c); alert(d); }); a,b,c 三个变量被成功赋值,值就是 数组 arr 的 阅读全文
posted @ 2023-07-06 17:08 luytest 阅读(4) 评论(0) 推荐(0) 编辑
摘要: Let,Const,Var 可以放一起说 这三个都是JS中用来声明变量的关键字。 主要的区别是 1.作用域 Var声明的变量的作用域是当前的执行上下文,也就是说,如果在函数外部声明,则是全局变量,如果是函数内部声明,则是整个函数块的变量。 Let声明的变量的作用域则是当前的代码块,也就是说可以像va 阅读全文
posted @ 2023-07-06 16:08 luytest 阅读(10) 评论(0) 推荐(0) 编辑