Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created November 12, 2018 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/dbd29269e628870f3c6aa670035918dd to your computer and use it in GitHub Desktop.
Save tomhodgins/dbd29269e628870f3c6aa670035918dd to your computer and use it in GitHub Desktop.
// Option A
window.addEventListener('touchstart', strike)
window.addEventListener('mousedown', strike)
window.addEventListener('touchmove', slide)
window.addEventListener('mousemove', slide)
window.addEventListener('touchend', release)
window.addEventListener('mouseup', release)
document.querySelector('select').addEventListener(
'change',
event => oscillator.type = event.target.value
)
document.querySelector('[type="range"]').addEventListener(
'input',
event => volume = event.target.value
)
// Option B
[
{
target: window,
event: 'touchstart',
action: strike
},
{
target: window,
event: 'mousedown',
action: strike
},
{
target: window,
event: 'touchmove',
action: slide
},
{
target: window,
event: 'mousemove',
action: slide
},
{
target: window,
event: 'touchend',
action: release
},
{
target: window,
event: 'mouseup',
action: release
},
{
target: document.querySelector('select'),
event: 'change',
action: event => oscillator.type = event.target.value
},
{
target: document.querySelector('[type="range"]'),
event: 'input',
action: event => volume = event.target.value
}
].forEach(action =>
action.target.addEventListener(action.event, action.action)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment