Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Created September 13, 2016 14:34
Show Gist options
  • Save jacopotarantino/6a8d2caac5a1dc926d6e269a1cd1306d to your computer and use it in GitHub Desktop.
Save jacopotarantino/6a8d2caac5a1dc926d6e269a1cd1306d to your computer and use it in GitHub Desktop.
different styles of writing getters and setters in es6
// java style
export class PWOService {
private selectedStyle;
public storeSelectedStyle(style) {
this.selectedStyle = style;
}
public getSelectedStyle() {
return this.selectedStyle;
}
}
// jquery style
export class PWOService {
private _selectedStyle;
public selectedStyle(style) {
if (style) {
_selectedStyle = style
} else {
return _selectedStyle;
}
}
}
// es6 proxy style
export class PWOService {
private _selectedStyle;
set selectedStyle(style) {
this._selectedStyle = style;
emit()
}
get selectedStyle() {
return this._selectedStyle;
counter.increment()
}
}
// minimal style
export class PWOService {
public selectedStyle;
}
// observables?
export class PWOService {
private selectedStyle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment