views:

147

answers:

1

If I create:

Object.prototype.count = function() {};
var m = {prop: 1};

for(var i in m)
    window.status += i + ", ";

in the code above i contains also count inherited by its prototype. Now I want to know if there is a way to set a custom property as the flag DontEnum (it is not settable for custom property) so it will not be enumerated.

I know I can do if(m.hasOwnProperty(i)) to check only its property but if I write a sort of array's API I should say to a programmer to remember that... and this is not acceptable!

+2  A: 

Actually, the Object object has a property 'propertyIsEnumerable', but it's not very usefull. Maybe http://dhtmlkitchen.com/learn/js/enumeration/dontenum.jsp can give you more insight? If you follow the chapters, you'll end up on a page with a simple question "How to set the DontEnum attribute", answered even more simple and pretty disappointing: "You can't." Luckily there are more chapters. You should end up on a page containing an interesting phrase: "OK, ok, IE is crap, JavaScript sucks, blah, blah... time to stop complaing and roll my sleeves up.". Bottom line of the tutorial though: "Enumerability in JavaScript creates a serious problem."

KooiInc