Hacker News new | ask | show | jobs
by mauvia 776 days ago
I feel like the bit flags structure of this event isn't Javascript-y because javascript doesn't support int primitives. Wonder why they didn't translate it.
1 comments

I think it's elegant actually. Appropriate and a nice link with "device driver" stuff from the past. :) haha

At least they didn't overcomplicate it. I shudder to think of: MouseEvent.MIDDLE_BUTTON_PRESSED etcs.

It could work as an Array if javascript supports C++'s small-buffer-optimization on the backend.
That's what I thought it was, based on the name. But more interesting to see the bitmask heh :) I don't know about C++ internal, but in JS you can just go

  if ( mousedown.buttons & 4 ) alert('aux pressed')
Tho thinking of it now as you mentioned array I'd feel mousedown.buttons.includes(4) would be slightly inefficient due to the loop. We like our efficiency! Haha :)

For me tho the API feels right for JS. As it's kind of a rare a 'low level' thing, it's appropriate it's API is more akin to that than something heavier like

  MouseEvent.buttons.<button> = Boolean
I like the efficiency of the bit mask to immediately check multiple buttons too :) haha
how is a magic "4" better than MouseEvent.MIDDLE_BUTTON_PRESSED?
Heheheh. Well I guess we're getting down into the weeds now and into the aesthetics of it which are nevertheless personal.

To me, it's obscene and ugly. Over the top. 4 isn't so magic when you realize that the middle button is normally considered the 3rd after the first and second buttons. And when you stretch those values into a bit field, with zero representing nothing, it's natural that the middle (or aux button) will occupy 4.

Hahaha! :) At least to my thinking. Hahaha :)

What do you think? :)