I find this code confusing-
let ownProps = [];
let prototypeProps = [];
for (let property in duck) {
if(duck.hasOwnProperty(property)) {
ownProps.push(property);
} else {
prototypeProps.push(property);
}
}
It is said that console.log(ownProps)
would
display ["name"]
in the console,
and console.log(prototypeProps)
would display ["numLegs"]
.
As far as I know, if the first statement is
true, the statement under else do not run. Here
the first statement is true because duck
instance will automatically have its own
property because it is an instance of Bird,
so console.log(ownProps) will display [name]
but why statement under else is also executed? when it should not be.
Can you please clarify?