On Sun, Feb 12, 2012 at 12:09 PM, Marcel Laverdet <mar...@laverdet.com> wrote: > This is one of those old Crockfordisms that I definitely don't agree with. > How about instead you just don't add garbage to Object.prototype?
Depends on how much control you have over all the code in your environment. Things are somewhat better in Node land, but in browser land, all it takes is some library you're using that augments Object.prototype and you're hosed unless you protect your own enumerations from such augmentation. -- Martin Cooper > Or if you > do make them DontEnum. Do you really write two-line loop headers every time > you want a loop?? > > > On Sun, Feb 12, 2012 at 6:42 AM, Shimon Doodkin <helpmep...@gmail.com> > wrote: >> >> for (var key in myobj) must be accompanied with >> if(Object.hasOwnProperty.call(myobj,key)) >> >> example: >> >> for (var key in myobject) { >> if(Object.hasOwnProperty.call(myobject,key)){ >> ... >> } >> } >> >> myobject.forEach(function(){...}) already does this. >> >> >> more: >> >> You could do : myobj.hasOwnProperty(key) But then if myobj is NULL it >> will throw an error. >> So you use the method hasOwnProperty from the prototype object. >> and you call it with changing the this object of it to your object. >> >> Object.hasOwnProperty.call(myobj,key) >> >> Most of you probably know this, but sometimes I encounter modules that >> don't do this. >> And they do unexpected errors. >> >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> You received this message because you are subscribed to the Google >> Groups "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com >> To unsubscribe from this group, send email to >> nodejs+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en > > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en