Added missing hasOwnProperty check into for-each

Without these checks, things break if someone adds properties to Object.prototype.