When JavaScript is looking for a property, it first looks into the object itself. If it isn't there, it normally keeps walking up the prototype chain. hasOwnProperty
exists to check only the object itself, explicitly not walking up the prototype chain. If you want to check if a property exists at all, checking everything in the prototype chain, use the in
operator:
'sayName' in penguin // => true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…