zizxzy

Results 17 comments of zizxzy

```js // 给定一个数组,按找到每个元素右侧第一个比它大的数字,没有的话返回-1 规则返回一个数 const findRightFristMax = (arr) => { let result = []; const len = arr.length; for (let i = 0; i < len - 1; i++) {...

```js Array.prototype.myFlat1 = function () { return this.reduce((acc, cur) => { return acc.concat(cur); }, []); }; const arr = [1, 2, [3, 4]]; console.log(arr.myFlat1()); Array.prototype.myFlat2 = function (depth = 1)...

订阅和发布的关键在利用一个对象或者map存储事件对象,on是添加事件,off是删除事件,emit是遍历事件对象然后调用 ```js class EventEmitter { constructor() { this.event = {}; } on(eventName, callbackFunc) { const callback = this.event[eventName] || []; if (Array.isArray(callback)) { callback.push(callbackFunc); this.event[eventName] = callback; } return this.event;...

proxy的介绍[proxy](https://es6.ruanyifeng.com/?search=proxy&x=0&y=0#docs/proxy) 利用proxy重写[] ```js const negativeIndex = arr => { return new Proxy(arr, { get: (target, proKey) => { let index = Number(proKey); let length = target.length; while (index < 0)...

Hello I have the same problem,have you solve it?

```js // this的指向问题,箭头函数不会创建自己的this,它只会从自己的作用域链的上一层继承this var obj = { i: 10, b: () => console.log(this.i, this), c: function () { console.log(this.i, this) } } obj.b(); // undefined, {} node 环境 obj.c(); //...

链式调用的关键在于返回自身this,便于后面继续调用