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求解
React-Redux shallowEqual方法是不是錯了?
一只斗牛犬
2018-10-19 11:10:50