Skip to content

Instantly share code, notes, and snippets.

@shcyiza
Last active May 26, 2022 08:36
Show Gist options
  • Save shcyiza/f982bc6adeeefaf905bffd9692343b1f to your computer and use it in GitHub Desktop.
Save shcyiza/f982bc6adeeefaf905bffd9692343b1f to your computer and use it in GitHub Desktop.
showing off how to dynamically invoke function in JS
const OAUTH2_OPTIONS = {
facebookLogin() {
// do the oath2 procedure for FB
},
googleLogin() {
// do the oath2 procedure for google
},
instagramLogin() {
// do the oath2 procedure for instagram
}
}
function dispatchSocial(social) {
const valid_socials = ["facebook", "google", "instagram"]
if (valid_socials.includes(social)) { // validate social argument before execution
OUATH2_OPTIONS[social + "Login"]() // calling the logins method dynamically here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment