You could combine both ideas with Object.assign:
function Something(defaultFoo) {
var _foo = defaultFoo;
Object.assign(this, {
get Foo() { return _foo; },
set Foo(value) { _foo = value; }
});
}
Make sure, however, that the link _foois the same as this, and not how this._foo, since you never defined it.
, ES6, - this._foo:
class Something {
constructor(defaultFoo) {
this._foo = defaultFoo;
}
get Foo() { return this._foo; }
set Foo(value) { this._foo = value; }
}