摘要: 在遵循团队规范的前提下阅读 1 命名 1.1 文件命名 不使用大写,除非框架特别约定组件首字母大写; 特别提醒的文件名可采用大写如:README.md; 1.2 文件夹命名 使用复数单词,多单词用连接符-连接;如:pages,images 使用单词简写时,不用加复数;如:css,img 均使用小写; 阅读全文
posted @ 2021-01-06 17:00 liaoing 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 看到群里发的一个问题,为什么 [] == ![] 输出是true? 看到了第一反应是黑人问号脸?但是得信,JavaScript无所不坑,就试着去寻找答案。 ! 的优先级比 == 要高,所以会先执行 ! [] 。 ! [] :是[]取反,[]的转换成布尔值类型是:true ,因为:空字符串' ',un 阅读全文
posted @ 2021-01-05 20:50 liaoing 阅读(224) 评论(0) 推荐(0) 编辑
摘要: javascript准确判断各种数据类型 Object.prototype.toString.call() 方法 判断基本数据类型 const a = Object.prototype.toString.call(null) console.log(a) // [object Null] conso 阅读全文
posted @ 2021-01-05 11:10 liaoing 阅读(105) 评论(0) 推荐(0) 编辑
摘要: JavaScript数组扁平化常用方法 1、toString const array = [1, 2, 3, [4, 5, [6, 7]]] const flatten = array.toString().split(',') 2、join const arr = [1, 2, 3, [4, 5, 阅读全文
posted @ 2021-01-04 18:54 liaoing 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 对于数组的操作,就常用的方法进行总结 首先判断是否是数组的方法: Array.isArray() 用于确定传递的值是否是一个 Array。 如果值是 Array,则为true; 否则为false。 扩展运算符 找出数组中最大或最小值 const arr = [2, 8, 15, 4]; Math.m 阅读全文
posted @ 2021-01-04 17:45 liaoing 阅读(139) 评论(0) 推荐(0) 编辑
摘要: JavaScript中??符号, Null 判断运算符 作用:读取对象属性的时候,如果某个属性的值是null或undefined,有时候需要为它们指定默认值。以前做法是通过双管道符号 || 运算符指定默认值。 // 通过||运算符指定默认值,属性的值如果为''或false或0,默认值也会生效。 co 阅读全文
posted @ 2021-01-04 11:52 liaoing 阅读(439) 评论(0) 推荐(0) 编辑
摘要: 函数参数解构 function sayHi({ name, age }: any) { console.log(`Hi, ${name}, ${age}`); } sayHi({ name: 'ANDY', age: 18 }); 阅读全文
posted @ 2020-12-11 11:51 liaoing 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 优雅编程 1 判断不是空数组,做一些事情 // bad if (arr.length !== 0) { // todo } // good if (arr.length) { // todo } 2 使用includes简化if判断 // bad if (a 1 || a 2 || a 3 || a 阅读全文
posted @ 2020-12-09 15:25 liaoing 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 转成布尔值 1.通过!!转换 2.通过Boolean( ) ⭐️ 注:undefined,null,-0,+0,NaN,‘’(空字符串)是false,其他的都是true。 所有对象的布尔值都是true,甚至连false对应的布尔对象也是true。空对象和空数组[]也会被转成true。 number类 阅读全文
posted @ 2020-12-09 14:53 liaoing 阅读(139) 评论(0) 推荐(0) 编辑
摘要: const obj = 1.toString(推荐) Object.prototype.toString.call(obj) '[object Object]' 2.constructor obj.constructor Object obj?.constructor Object 3.instan 阅读全文
posted @ 2020-12-09 14:09 liaoing 阅读(12784) 评论(0) 推荐(0) 编辑