Skip to content

Comment on Google Closure: How not to write Javascript

Comments

If you want to super careful, obj.hasOwnProperty(key) is actually dangerous. What happens when obj has it's own property named "hasOwnProperty"?

The safest thing to do is:

    Object.prototype.hasOwnProperty(obj, key)
Of course, as with the "undefined" example, malicious or incompetent code could overwrite Object.prototype.hasOwnProperty
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.