I understand why hasOwnProperty is necessary even when one has complete control over an object, since Object.prototype may have been modified. But if I really want to avoid it, consider this:
function CleanObject() {
var result = {};
for (var key in result) {
delete result[key];
}
return result;
}
// Later...
var obj = CleanObject();
for (var key in obj) {
// No hasOwnProperty check necessary
}
In other words I'm clearing the instance of properties before using it. Should this work, or am I missing some edge-case?