In the eslint rule guard-for-in , use for in
directly is incorrect. The good practice is
for (key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
if ({}.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
My question is when Object.prototype.hasOwnProperty.call(foo, key)
and {}.hasOwnProperty.call(foo, key)
will lead different result? Anyone can show a specific example?