随笔分类 -  JavaScript

摘要:// map 方法,对数组进行循环操作 并传入一个新的数组 const movements = [200, 450, -400, 3000, -650, -130, 70, 1300]; const eurToUsd = 1.1; // const movementsUSD = movements. 阅读全文
posted @ 2022-07-12 13:55 吃惊夜夜 阅读(76) 评论(0) 推荐(0) 编辑
摘要:const secureBooking = function () { // 调用这个函数 这个值外部无法访问 let passengerCount = 0; return function () { passengerCount++; console.log(`${passengerCount} 阅读全文
posted @ 2022-07-11 20:38 吃惊夜夜 阅读(64) 评论(0) 推荐(0) 编辑
摘要:ES6如何选择数据结构, 每种数据结构的优缺点; 基本上有三种数据来源 1、可以写入数据,在程序源代码本身,如状态消息,将根据用户操作显示在网页上 2、数据可以来自用户界面 3、数据来自外部来源,通常是来自一个WebAPI 我们需要储存在某个地方,Javascript有四种内置的数据结构,所以需要在 阅读全文
posted @ 2022-07-07 20:25 吃惊夜夜 阅读(36) 评论(0) 推荐(0) 编辑
摘要:// ES6 map数据类型 const rest = new Map(); // 使用set()方法填充数据 set()方法返回更新后的全部数据; rest.set('name', 'Classico Italiano'); rest.set(1, 'Firenze,Ttaly'); consol 阅读全文
posted @ 2022-07-07 19:29 吃惊夜夜 阅读(149) 评论(0) 推荐(0) 编辑
摘要:// ES6 Set集合数据类型 const ordersSet = new Set([ 'Pasta', 'Pizza', 'Pizza', 'Risotto', 'Pasta', 'Pizza', ]); // 只会显示不重复的数据 console.log(ordersSet); // 集合可拆 阅读全文
posted @ 2022-07-07 17:19 吃惊夜夜 阅读(38) 评论(0) 推荐(0) 编辑
摘要:// 可选链接 ?. console.log(restaurant.openinghours.mon?.open); console.log(restaurant.openinghours?.mon?.open); const days = ['mon', 'tue', 'web', 'thu', 阅读全文
posted @ 2022-07-07 00:57 吃惊夜夜 阅读(131) 评论(0) 推荐(0) 编辑
摘要:/** * 统计区分中英文字符字数 */function getWordsCnt(str){ var n = 0; for(var i=0;i<str.length;i++){ var ch = str.charCodeAt(i); if(ch > 255){ // 中文字符集 n+=2; }els 阅读全文
posted @ 2022-05-25 14:28 吃惊夜夜 阅读(272) 评论(0) 推荐(0) 编辑
摘要:引入swiper组件库点击第一个或者最后一个居中左右留白的问题。 var mySwiper = new Swiper('.swiper-container2', { slideToClickedSlide: true, //开启点谁谁居中 centeredSlides: true, // 居中 sl 阅读全文
posted @ 2022-04-29 10:38 吃惊夜夜 阅读(410) 评论(0) 推荐(0) 编辑
摘要:常用正则表达式合集:验证数字:^[0-9]*$验证n位的数字:^\d{n}$验证至少n位数字:^\d{n,}$验证m-n位的数字:^\d{m,n}$验证零和非零开头的数字:^(0|[1-9][0-9]*)$验证有两位小数的正实数:^[0-9]+(.[0-9]{2})?$验证有1-3位小数的正实数:^ 阅读全文
posted @ 2021-09-15 09:42 吃惊夜夜 阅读(307) 评论(0) 推荐(0) 编辑
摘要:1.js中继承的终极方法1.1在子类的构造函数中通过call借助父类的构造函数1.2将子类的原型对象修改为父类的实例对象 function Person(myName,myAge) { // let per = new Object(); // let this = per; // this = s 阅读全文
posted @ 2021-08-17 00:30 吃惊夜夜 阅读(31) 评论(0) 推荐(0) 编辑
摘要:1.所有的构造函数都有一个prototype属性, 所有prototype属性都指向自己的原型对象2,所有的原型对象都有一个constructor属性, 所有constructor属性都指向自己的构造函数3.所有函数都是Function构造函数的实例对象4.所有函数都是对象, 包括Function构 阅读全文
posted @ 2021-08-15 23:16 吃惊夜夜 阅读(378) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示