08 2023 档案
摘要:```` //类的定义 //定义一个动物类 function Animal(name){ //属性 this.name=name||"Animal" //实例方法 this.sleep=function(){ console.log(this.name+'在睡觉') } } //原型方法 Anima
阅读全文
摘要:```` let arr=[1,2,2,2,3,4,5,5]; let arr1=[] //方法1 indexOf去重 arr.map(e=>{ if(arr1.indexOf(e) 1){ arr1.push(e) } }) console.log(arr1) //方法2 es6 set去重 le
阅读全文
摘要:```` let obj={ a:1, b:2, c:3 } //方法1 let obj1=JSON.parse(JSON.stringify(obj)) obj1.a=10 console.log(obj); console.log(obj1); //方法2 function deepClone(
阅读全文
摘要:```` //利用闭包延长变量的生命周期 function once(func){ let flag=true return function increment(){ if(!flag){ return increment.value } flag=false increment.value=fu
阅读全文