js
可爱的小前端
这个作者很懒,什么都没留下…
展开
-
WeakMap学习思考- Map、WeakMap、强引用 、弱引用和垃圾回收
WeakMap学习思考MapMap的问题在于A map API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the four API methods. Setting elements on this map would involve pushing a key and value onto the end of each of those arrays sim原创 2021-12-25 12:57:28 · 398 阅读 · 0 评论 -
js 扁平化嵌套数组
不使用额外的入参 递归函数返回扁平化后的数组var arr1 = [ 22, [33, 44], [55, 66], [[77, 88, [99, 100, [101], 102]]], 103, [104, 105], 106, 107]function flat (data, flatArray = []) { let flatAll = flatArray for (let i = 0; i < data.length; i++) { .原创 2021-12-05 12:17:57 · 652 阅读 · 0 评论 -
求数组嵌套的最大深度
整体思路就是得到每次循环的层数 并且和当前得到的最大层数做比较问题 如何不用外部变量获得最大深度 想减少一个函数入参,并且能把最大值直接返回var arr1 = [ 22, [33, 44], [55, 66], [[77, 88, [99, 100, [101], 102]]], 103, [104, 105], 106, 107]var arr2 = [1, [2, 4], 3]function multiarr (arr, level = 0) {原创 2021-12-02 10:36:56 · 533 阅读 · 0 评论 -
手写 promise
class Commitment { static PENDING = '待定' static FULFILLED = '成功' static REJECTED = '失败' constructor (func) { this.status = Commitment.PENDING this.result = null this.resolveCallbacks = [] this.rejectCallbacks = [] //处理直接抛出错误 t.原创 2021-11-07 14:59:59 · 51 阅读 · 0 评论 -
手写bind, call, apply
隐式绑定当函数作为引用属性被添加到对象中,隐式绑定规则会把函数调用中的this绑定到这个上下文对象显示绑定运用apply call 方法,在调用函数时候绑定this,也就是指定调用的函数的this值const module = { x: 42, getX: function() { return this.x; }};const unboundGetX = module.getX;console.log(unboundGetX()); // The func..原创 2021-11-05 12:00:57 · 39 阅读 · 0 评论