{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2839","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2839/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2839/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2839/events","html_url":"https://github.com/Automattic/mongoose/issues/2839","id":66539859,"number":2839,"title":"Getter/setter: property name as argument","user":{"login":"bathos","id":6257356,"avatar_url":"https://avatars.githubusercontent.com/u/6257356?v=3","gravatar_id":"","url":"https://api.github.com/users/bathos","html_url":"https://github.com/bathos","followers_url":"https://api.github.com/users/bathos/followers","following_url":"https://api.github.com/users/bathos/following{/other_user}","gists_url":"https://api.github.com/users/bathos/gists{/gist_id}","starred_url":"https://api.github.com/users/bathos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bathos/subscriptions","organizations_url":"https://api.github.com/users/bathos/orgs","repos_url":"https://api.github.com/users/bathos/repos","events_url":"https://api.github.com/users/bathos/events{/privacy}","received_events_url":"https://api.github.com/users/bathos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-06T06:29:28Z","updated_at":"2015-04-06T19:03:45Z","closed_at":null,"body":"At present, at least according to the docs, when you assign a getter or setter in a schema property definition, fn receives no arguments; all you have to work with is the document via 'this'. It would be nice to receive as an argument the name of the property, because then we could define generic, reusable get functions that can define behaviors for a repeatable type rather than a specific property that needs to be known beforehand.\r\n\r\nExample:\r\n\r\n    var momentDate = {\r\n        type: Date,\r\n        get: prop: function(prop) { return moment.utc(this[prop]); }\r\n        set: function(val, prop) { this[prop] = moment.isMoment(val) ? val.toDate : val; },\r\n        validate: function(val) { return moment.utc(val).isValid(); }\r\n    };\r\n\r\n    var schema = new moment.Schema({\r\n        start: momentDate,\r\n        end: momentDate\r\n    });"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/90199798","html_url":"https://github.com/Automattic/mongoose/issues/2839#issuecomment-90199798","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/2839","id":90199798,"user":{"login":"bathos","id":6257356,"avatar_url":"https://avatars.githubusercontent.com/u/6257356?v=3","gravatar_id":"","url":"https://api.github.com/users/bathos","html_url":"https://github.com/bathos","followers_url":"https://api.github.com/users/bathos/followers","following_url":"https://api.github.com/users/bathos/following{/other_user}","gists_url":"https://api.github.com/users/bathos/gists{/gist_id}","starred_url":"https://api.github.com/users/bathos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bathos/subscriptions","organizations_url":"https://api.github.com/users/bathos/orgs","repos_url":"https://api.github.com/users/bathos/repos","events_url":"https://api.github.com/users/bathos/events{/privacy}","received_events_url":"https://api.github.com/users/bathos/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T19:03:45Z","updated_at":"2015-04-06T19:03:45Z","body":"Thanks, @Prinzhorn, you're correct. And in the links there I see that get *does* get a second argument already with the additional info I was seeking. Turns out I was looking at the wrong docs -- for some reason I kept checking the section on virtuals (which also have get/set) and never ended up in the right place till now."}}