https://gist.github.com/1427331
function makeNonEnumerable(obj /*, props */) { var names = [].slice.call(arguments, 1); names.forEach(makeNonEnumerable); function makeNonEnumerable(name) { var pd = Object.getOwnPropertyDescriptor(obj, name); pd.enumerable = false; Object.defineProperty(obj, name, pd); } } makeNonEnumerable(colors, "length", "currentColor"); On Sat, Dec 3, 2011 at 2:59 PM, Jarek Foksa <ja...@kiwi-themes.com> wrote: > Lets say I want to create "colors" collection. The color names inside > the collection > should be enumerable, while "length" and "currentColor" should not be > enumerable: > > var colors = { > // enumerable properties > black: '#000', > white: '#fff', > blue: '#343', > } > // non-enumerable properties > Object.defineProperty(colors, 'currentColor', { value : 'green', > writable : true, enumerable : false, configurable : true}); > Object.defineProperty(colors, 'length', { value : 3, writable : true, > enumerable : false, configurable : true}); > > This code works as expected, but it's hard to read because of the > verbose descriptor syntax. Is it possible > to specify which properties should not be enumerable after they were > defined? > > var colors: { > black: '#000', > white: '#fff', > blue: '#343', > currentColor: 'green', > length: 3, > } > > makeNonEnumerable(names.currentColor, names.length); > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/jsmentors@jsmentors.com/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/jsmentors@googlegroups.com/ > > To unsubscribe from this group, send email to > jsmentors+unsubscr...@googlegroups.com > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com