I am now learning about HTML5 Web Workers and I don't understand one small "stylistic" thing.
Why is onmessage
with small m
in message
, but postMessage
has capital M
?
Is there some reason for this decision? I cannot find it.
I don't want an opinion on the styling, just some reasonable explanation.
camelCase is definitely the preferred convention for JavaScript. However, DOM events have been lowercase for a long time (javascript/DOM event name convention posits a connection to case-insensitive HTML attribute names) and have remained that way for backwards compatibility for legacy browsers, and new events continue to follow that convention for consistency.
Check out MDN's list of global event handlers - onload
, onerror
, onmousedown
, etc. This convention seems to have carried over into event names for things other than DOM events, but for stuff other than events, like the postMessage
function, the camelCase convention remains.