Doable with "old" JS. Consider this function:
function prop(name, gNs) {
var _name = '_' + name,
get = gNs && gNs.get,
set = gNs && gNs.set,
undef = function (v) { return typeof v == 'undefined'; },
if (get && set)
return function (x) { return undef(x) ? get.call(this, this[_name]) : (this[_name] = set.call(this, x), this); }
if (get && !set)
return function (x) { return undef(x) ? get.call(this, this[_name]) : (this[_name] = x, this); }
if (!get && set)
return function (x) { return undef(x) ? this[_name] : (this[_name] = set.call(this, x), this); }
return function (x) { return undef(x) ? this[_name] : (this[_name] = x, this); }
}
Pass `prop` (a) the name of a property you're defining getter/setter methods for and (b) an object with any custom getter/setter you might care to define (or neither, if you like), and it'll return a function that will act as both which you can assign to a prototype.