摘要:
bind返回一个函数 闭包保存this, 执行的时候用apply或call绑定this js中new的优先级高于bind Function.prototype._bind = function (context) { if (typeof this !== "function") throw "ty 阅读全文
posted @ 2022-06-14 18:24
IslandZzzz
阅读(38)
评论(0)
推荐(0)
摘要:
比较麻烦的是this指向的问题,但是可以通过"对象的函数调用指向对象自身"来处理 如果没有传入context, 那么this默认指向window Function.prototype._call = function (context) { const type = typeof this if ( 阅读全文
posted @ 2022-06-14 17:33
IslandZzzz
阅读(25)
评论(0)
推荐(0)
摘要:
js 手写类型判断函数 判断引用类型 调用Object.prototype.toString截取字符串 判断基本类型 返回typeof function getType(target) { if (target null) { return "null" } // 引用类型 if (typeof t 阅读全文
posted @ 2022-06-14 17:04
IslandZzzz
阅读(137)
评论(0)
推荐(0)
摘要:
手写防抖 如果存在之前的计时器,取消重新计时。 即多次点击只执行最后一次 注意this指向和回调形参列表 <button onclick="clickMe(1)">click me</button> <script> const clickMe = debounce((a) => { console 阅读全文
posted @ 2022-06-14 16:23
IslandZzzz
阅读(52)
评论(0)
推荐(0)
摘要:
入参必须实现iterator接口,一般为一个非空数组 返回一个promise, 结果为数组中第一个改变为成功/失败状态的那个promise元素 Promise._race = function (promises) { if (!promises instanceof Array || !promi 阅读全文
posted @ 2022-06-14 16:01
IslandZzzz
阅读(198)
评论(0)
推荐(0)
摘要:
入参必须实现iterator接口,一般为数组 全部成功才算成功,有一个失败就失败, 如果成功,结果顺序和入参顺序保持一致 返回一个新的promise, Promise._all = function (promises) { if (!promises instanceof Array) throw 阅读全文
posted @ 2022-06-14 15:51
IslandZzzz
阅读(104)
评论(0)
推荐(0)
摘要:
Promise状态枚举 收集状态更改的回调函数到数组里 实现resolve,reject, 注意校验状态为pending 执行Promise形参函数,传入resolve,reject const statusMap = { PENDING: 'PENDING', RESOLVED: 'RESOLVE 阅读全文
posted @ 2022-06-14 15:10
IslandZzzz
阅读(142)
评论(0)
推荐(0)

浙公网安备 33010602011771号