JSFiddle - React, Tailwind, and code Playground
by JakobJingleheimer
JavaScript
function LocaleService(PrefService) {
Object.defineProperties(LocaleService.prototype, {
pref: {
configurable: false,
enumerable: true,
get: function() { return PrefService.getLocale() },
set: function(locale) { return PrefService.setLocale(locale) }
}
});
}
function PrefService() {
this._prefs = {
locale: 'en_US'
};
}
PrefService.prototype.getLocale = function getLocalePref() {
return this._prefs.locale;
};
PrefService.prototype.setLocale = function setLocalePref(locale) {
this._prefs.locale = locale;
};
var prefService = new PrefService();
var localeService = new LocaleService(prefService);
console.log(localeService.pref);
localeService.pref = 'fr_CH';
console.log(localeService.pref);