Created
September 13, 2016 14:34
-
-
Save jacopotarantino/6a8d2caac5a1dc926d6e269a1cd1306d to your computer and use it in GitHub Desktop.
different styles of writing getters and setters in es6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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