Skip to content

Instantly share code, notes, and snippets.

@simodima
Created June 22, 2016 09:04
Show Gist options
  • Save simodima/4c40d700b6f9f17bca24e52c602030d0 to your computer and use it in GitHub Desktop.
Save simodima/4c40d700b6f9f17bca24e52c602030d0 to your computer and use it in GitHub Desktop.
> const strategies = {
first: () => {},
second: () => {},
undefined: () => 'default'
};
> const obj0 = { type: 'first' };
> const obj1 = { };
> console.log(strategies[obj1.type]());
default
> console.log(strategies[obj0.type]());
undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment