app .factory('Variable', function (RewriteService) { var defaultValues = { name: '', defaultValue: '', placeholder: '', type: null }; var Variable = function (values) { angular.copy(angular.extend({}, defaultValues, values || {'new': true}), this); if (!angular.isArray(this.values)) { this.values = []; } }; Object.defineProperty(Variable.prototype, 'Rewrite', { get: function () { if (!this.name) { return null; } delete this.new; this.rewrite = RewriteService.transform(this.name, '_'); return this.rewrite; } }); return Variable; });