function Filter() { this.items = []; } Object.defineProperty(Filter.prototype, 'count', { get: function() { return this.items.length; } }); var f = new Filter(); f.items.push(123); alert(f.count);