- 博客(6)
- 收藏
- 关注
原创 Promise.all哪怕一个请求失败了也能得到其余正确的请求结果的解决方案
Promise.all( [ Promise.reject({ code: 500, msg: "服务异常" }), Promise.resolve({ code: 200, list: [] }), Promise.resolve({ code: 200, list: [] }) ].map(p => p.catch(e => e))) .the...
2020-03-23 16:14:40
6983
原创 a == 1 && a == 2 && a == 3为true
三种实现方式let a = { i: 1, toString: function() { return this.i++; }};let a = new Proxy({}, { i: 1, get: function() { return () => this.i++ } });//数组的 toString 默认调用数...
2020-03-17 14:17:50
161
原创 深拷贝
function deepClone(obj) { function isObject(o) { return (typeof o === "object" || typeof o === "function") && o !== null; } if (!isObject(obj)) { throw new Error("非对象"); } le...
2020-03-17 14:12:50
105
1
原创 new的实现原理
// 创建一个空的新对象// 链接到原型// 绑定this// 返回新对象function _new() { let obj = {}; let [constructor, ...args] = [...arguments]; obj.__proto__ = constructor.prototype; let result = constructor.apply(obj...
2020-03-16 18:34:38
164
原创 instanceof 的原理
instanceof 可以正确的判断对象的类型,因为内部机制是通过判断对象的原型链中是不是能找到类型的 prototype。instanceof 实现如下:function myInstanceof(left, right) { var prototype = right.prototype var left = left.__proto__ while (true) { i...
2020-01-07 15:03:32
182
原创 call,apply和bind原生实现
call实现Function.prototype.newCall = function (context, ...parameter) { if (typeof context === 'object' || typeof context === 'function') { context = context || window } else { context ...
2020-01-05 18:37:45
106
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人