My post mainly about loops, not about prototypes. To not use prototypes when you write a plugin script to be integrated into 3rd parity website is a very good idea.
Generaly Node.js is very controlled-settings environment. I like to add some agile convenience by using prototypes, I add them to to Strings and sometimes to Objects, to modernize JavaScript a little bit. For me, it's worth it. ------- Bradley Griffiths, Joe Developer: Awesome about Tim Caswell's message about missing Object.keys: The better compatibility implementations are found at Mozilla Developer Network website https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys Marcel Laverdet: Humm, interesting, I see what you mean: Object.prototype.defineProperty(obj, "newDataProperty", { value: function(){}, writable: false, enumerable: false, configurable: true });// from: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty Thanks, real value to the conversation However I am concerned about: Maybe a loop should not iterate on prototype's properties. Thanks Everybody. On Feb 12, 4:40 pm, Joe Developer <joe.d.develo...@gmail.com> wrote: > Requests for enlightenment: > > On Sun, Feb 12, 2012 at 7:42 PM, 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. > > Wouldn't it be more efficient to simply check if myobj is null before > trying to iterate over it? > In similar vein, wouldn't it be better to not declare the var inside the > for() in this instance? > > I realize that for the vast majority of cases the contents of the loop will > be far heavier than the scaffolding involved, but since we are presenting > 'best practice' scenarios for something that I would imagine would often > sit in a util function somewhere... > > I have created:http://jsperf.com/obj-property-iterationin case it might > have value, if nothing else to have a place to tack on various approaches. > > 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