摘要: new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。new 关键字会进行如下的操作: 创建一个空的简单JavaScript对象(即{}); 链接该对象(即设置该对象的构造函数)到另一个对象 ; 将步骤1新创建的对象作为this的上下文 ; 如果该函数没有返回对象,则返回th 阅读全文
posted @ 2020-07-10 22:03 朝思暮想的虫 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 1、call ~function(){ function call_1(context, ...args){ context = context == undefined ? window : context; let type = typeof context; if(!/^('object|fu 阅读全文
posted @ 2020-07-10 16:07 朝思暮想的虫 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 浅拷贝: 1、对象:Object.assign()、{...obj1} 2、数组:Array.prototype.slice(arr1) 深拷贝: 1、简单封装函数 function deepClone(obj){ if(obj null) return null; if(typeof obj != 阅读全文
posted @ 2020-07-10 15:06 朝思暮想的虫 阅读(141) 评论(0) 推荐(0) 编辑
摘要: function reduce(arr, callBack ,initVal){ if(!Array.isArray(arr) || !arr.length || typeof callBack != 'function') return []; let hasInitVal = initVal ! 阅读全文
posted @ 2020-07-10 11:55 朝思暮想的虫 阅读(737) 评论(0) 推荐(0) 编辑
摘要: const eventUtils = { // 绑定事件 addEvent(ele, type, handler){ if(ele.addEventListener{ ele.addEventListener(type, handler, false) }else if(ele.attachEven 阅读全文
posted @ 2020-07-10 11:15 朝思暮想的虫 阅读(185) 评论(0) 推荐(0) 编辑