I don’t quite understand the anonymous function ( function() {keyPlay(event)} ) within the eventAssign function on the Piano Keys project.
Prompt 4 and 5 ask to create 2 event handlers that run ‘keyPlay’ as an event handler when a ‘mousedown’ event fires on any note
and 'keyReturn as an event handler when a ‘mouseup’ event fires on any ‘note’.
The correct code block is:
eventAssign = note => {
note.onmousedown = function() {
keyPlay(event);
}
note.onmouseup = function() {
keyReturn(event);
}
}
This also works too:
eventAssign = note => {
note.onmousedown = keyPlay;
note.onmouseup = keyReturn;
}
BUT why doesn’t this work?:
eventAssign = note => {
note.onmousedown = keyPlay(event);
note.onmouseup = keyReturn(event);
}
AND what’s the difference between keyPlay and keyPlay(event)?