
js
zwwgoodwill
这个作者很懒,什么都没留下…
展开
-
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 · 7001 阅读 · 0 评论 -
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 · 165 阅读 · 0 评论 -
深拷贝
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 · 107 阅读 · 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 · 166 阅读 · 0 评论 -
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 · 186 阅读 · 0 评论 -
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 · 108 阅读 · 0 评论