js浅拷贝的作用

位置:首页 / 技术中心 / 杂项

杂项 Admin 2026-04-01 11:26:20 81

防止地址重复,防止修改同一个地址上的数据





// 导入 Node.js 自带的加密模块 const crypto = require('crypto'); let man={ name:"", birthDay:null, isHealth:null } let manList=[] // 定义一个 MD5 函数 function md5(str) { return crypto.createHash('md5').update(str).digest('hex'); } // 随机返回 true 或 false function randomBool(input) { return Math.random() > 0.5; } function makeMan(time){ const cardinalNumber =md5(time.toString()).slice(0,12) man.name = cardinalNumber man.birthDay = time man.isHealth = randomBool(time) manList.push({...man}) } function makeManPre(){ const num = 3 let numR = 0 // 每 1 秒执行一次 let timer=setInterval(() => { numR =numR + 1 if(numR === 12){ console.log("✅ 运行60秒,自动停止!"); console.log("最终总人数:", manList.length); clearInterval(timer); // ✅ 真正停止 return } console.log("✅ 每秒生成 3 个新人..."); for (let i = 0; i < num; i++) { let now = new Date(); makeMan(now); } console.log("当前总人数:", manList.length); console.log("最后3人:", manList); console.log("----------------------------------------"); }, 1000); // 1000毫秒 = 1秒 } function main(){ makeManPre() } main()

https://www.doubao.com/thread/wfcb6395ac6cfafa1


18455111359 扫描二维码