React Redux源码中(5.0.1),shallowEqual.js文件的代码看着很奇怪,是不是代码错误?还是我理解错误?const hasOwn = Object.prototype.hasOwnPropertyexport default function shallowEqual(a, b) { if (a === b) return true
let countA = 0
let countB = 0
for (let key in a) { if (hasOwn.call(a, key) && a[key] !== b[key]) return false
countA++ // 这里是不是应该检查ownProperty以后,再增加?
} for (let key in b) { if (hasOwn.call(b, key)) countB++
} return countA === countB
}疑问点看代码里面的注释,这样子会造成有从原型继承的属性是,永远是falseObject.prototype.bar = "bar";var a = { foo: 1 }; var b = { foo: 1 };
shallowEqual(a, b); // 永远是fales求解
添加回答
举报
0/150
提交
取消