Created
August 31, 2017 19:50
-
-
Save yuriploc/cbeb1f5e2d4225f395c82967ff2920bd to your computer and use it in GitHub Desktop.
which one? and why?
This file contains 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
// #1 - getter & setter | |
service.getPriceUpdatedAt = () => store.priceUpdatedAt | |
service.setPriceUpdatedAt = (tmstmp) => { | |
store.priceUpdatedAt = parseInt(tmstmp) | |
} | |
// #2 - 2in1 | |
service.priceUpdatedAt = (tmstmp) => { | |
if (!tmstmp) return store.priceUpdatedAt | |
else store.priceUpdatedAt = parseInt(tmstmp) | |
} |
I prefer the first, is auto explained and avoid mistake calls
and an third way is
service.priceUpdatedAt = {
get: () => store.priceUpdatedAt,
set: (tmstmp) => {
store.priceUpdatedAt = parseInt(tmstmp)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the second one, however i could embrace anything in use if there is an existing codebase