08 2020 档案
摘要:我们在使用new去创建构造函数的时候会经历四个步骤: 创建一个新对象 将构造函数的作用域赋值给新对象(因此this就指向了这个新对象) 执行构造函数中的代码(为这个新对象添加属性) 返回新对象 下面看一下代码实现: function my_new(Super, ...args) { const ob
阅读全文
摘要:const arr1 = [1,4,5,8,12,16,18] function binarySearch(arr, num) { let len = arr.length let leftIndex = 0 let rightIndex = len - 1 while(leftIndex <= r
阅读全文
摘要:Array.prototype.my_reduce = function(callBack, initValue) { if (typeof callBack !== 'function') { // 方法错误处理 throw new Error(`${callBack} is not a func
阅读全文
摘要:首先定义一下测试数据 const test = function(age, sex) { console.log(this.name, age, sex, 'test') } const person = { name: '毛小星' } 实现call方法 下面将自定义的call方法写在Functio
阅读全文
摘要:// Vue3.0 响应式原理 const toProxy = new WeakMap() // 放置的是 原对象:代理过的对象 防止多次代理同一个对象 const toRaw = new WeakMap() // 放置的是 代理过的对象:原对象 防止代理已经代理过的对象 // 判断是否为对象 fu
阅读全文
摘要:今天来实现一个简易版的Vue2.0响应式 class Vue { constructor(options) { this.$options = options this.$data = options.data // 重写数组方法 let arrayPrototype = Array.prototy
阅读全文
摘要:深度优先搜索和广度优先搜索是比较常见的算法,今天我们用js来实现以下 首先我们创建一下数据 const tree = { key: '第一层-1', children: [ { key: '第二层-1-1', children: [ { key: '第三层-1-1', children: [], }
阅读全文
摘要:Array.prototype.my_filter = function(fn, context) { let resArr = [] const me = this const ctx = context ? context : this // 判断上下文 if (typeof fn !== 'f
阅读全文
摘要:Array.prototype.my_map = function(fn, context) { let resArr = [] const me = this const ctx = context ? context : me // 定义上下文 if (typeof fn !== 'functi
阅读全文
摘要:vue2.0中去除了在v-html中使用filters方法,但是这是否意味着不可以这么使用了呢 html部分 <span v-html="$options.filters.contentFilters(item.data.description, this)" ></span> js部分 filte
阅读全文
摘要:周所周知,Vue在2.0版本中去除了$broadcast方法以及$dispatch方法,最近在学习饿了么的Element时重新实现了这两种方法,并以minix的方式引入。 废话不多说,上代码 function broadcast(componentName, eventName, params) {
阅读全文