Hacker News new | ask | show | jobs
by VeejayRampay 3709 days ago
Ruby: obj.each{|k,v| ...}

Sure you can do it in JS, but calling Object.keys then forEach (in whose closure you'll still have to reference obj[key] by the way) still doesn't feel optimal.

2 comments

In which case, if you really can't live without it, just attach it to the prototype.

Object.prototype.each = function(k,v){ //... }

I would argue that automatically adding methods to a user-created object isn't optimal either.