Skip to content

Instantly share code, notes, and snippets.

@yuriploc
Created August 31, 2017 19:50
Show Gist options
  • Save yuriploc/cbeb1f5e2d4225f395c82967ff2920bd to your computer and use it in GitHub Desktop.
Save yuriploc/cbeb1f5e2d4225f395c82967ff2920bd to your computer and use it in GitHub Desktop.
which one? and why?
// #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)
}
@sombriks
Copy link

I like the second one, however i could embrace anything in use if there is an existing codebase

@houstondapaz
Copy link

houstondapaz commented Sep 1, 2017

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