Subj : Re: Enumerate only direct properties of prototype, without chaining? To : Lev Serebryakov From : Brendan Eich Date : Mon Oct 03 2005 12:07 pm Lev Serebryakov wrote: > Is it possible to enumerate only direct properties of object and/or > its prototype? Enumeration like this: > > Object.prototype.a = "a"; > Object.prototype.b = "b"; > function Cls() { return this; }; > Cls.prototype = { c: "c" }; > for(p in Cls.prototype) { print(p," -> ", Cls.prototype[p], "\n" ) }; > > Show not only "c", but "a" and "b" as well. > > Is it possible to enumerate only direct properties, without traversing > prototype chain? No, but you can skip indirect properties by adding a o.hasOwnProperty(p) test when enumerating object o. /be .