随笔分类 -  js基础

摘要:class EventBus { constructor(){} handlerBus={} //注册 $on(eventName,handler){ if(!this.handlerBus.hasOwnProperty(eventName)){ this.handlerBus[eventName] 阅读全文
posted @ 2021-01-21 16:37 心中有一海 阅读(672) 评论(0) 推荐(0)
摘要:Object.freeze() 可以冻结一个对象。被冻结的对象有以下几个特点: 不能添加新属性 不能删除已有属性 不能修改已有属性的可枚举性、可配置性、可写性 不能修改已有属性的值 不能修改原型 属于浅冻结,复杂对象里面的对象仍然可以修改 我们知道,const本意是无法修改的一个值,但只对简单类型生 阅读全文
posted @ 2021-01-21 10:48 心中有一海 阅读(935) 评论(0) 推荐(0)
摘要://数组去重 const deduplication = arr => { //arr [1,2,1,2,3] let arrSet = new Set(arr) // arrSet Set:{1,2,3} return [...arrSet] } 阅读全文
posted @ 2020-12-23 21:59 心中有一海 阅读(83) 评论(0) 推荐(0)
摘要:语法window.requestAnimationFrame(callback) 会根据显示器的刷新率进行渲染,如果显示器是16ms刷新一次,那么window.requestAnimationFrame将会每16ms执行一次,这样避免了setTimeout可能出现的动画卡顿,丢帧的情况。 除了用于动 阅读全文
posted @ 2020-01-08 16:05 心中有一海 阅读(490) 评论(0) 推荐(0)
摘要:简单对象的深复制:JSON.parse(JSON.stringify(data)) 复杂对象的深复制: // 定义一个深拷贝函数 接收目标target参数 function deepClone(target) { // 定义一个变量 let result; // 如果当前需要深拷贝的是一个对象的话 阅读全文
posted @ 2020-01-08 15:49 心中有一海 阅读(227) 评论(0) 推荐(0)
摘要:function Cat(name,age){ this.name = name this.age= age } //机制1:每一个函数对象都有一个prototype对象 console.log(Cat.prototype) //node输出: {} Cat.prototype.get_name = function(){ return this.name } //机制2:new关键字+构造函数 阅读全文
posted @ 2019-10-14 00:37 心中有一海 阅读(788) 评论(0) 推荐(1)
摘要:function cat(age,color){ console.log(this) console.log(color) } const age1 = 1 const age2 =2 const color1 = 'white' const color2 = 'black' //1.函数直接调用: cat(age1,color1) /*node输出: this > 根据运行环境而定,指向当前运行 阅读全文
posted @ 2019-10-13 00:31 心中有一海 阅读(126) 评论(0) 推荐(0)