Skip to content

Dated and incorrect sample code in F99 #4344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
besenwagen opened this issue Apr 16, 2025 · 2 comments
Open

Dated and incorrect sample code in F99 #4344

besenwagen opened this issue Apr 16, 2025 · 2 comments

Comments

@besenwagen
Copy link

besenwagen commented Apr 16, 2025

F99 mentions to beware "the presence of the .keycode attribute".

  1. That looks like a DOM property accessor, and to the best of my knowledge, there is no (.)keycode attribute, assuming HTML is the host language. Note that DOM property accessors might yield different results than the getAttribute method for the reflected attribute.
  2. DOM property names are case sensitive: keyCode.
  3. keyCode has been deprecated since, eh, I'm not an archeologist. :-) A superficial search unveils a Stackoverflow question from 2016.
@bruce-usab
Copy link
Contributor

It looks to me like “the .keycode attribute” could be replaced by “event.key” -- but that is not an ambitious fix.

@besenwagen
Copy link
Author

besenwagen commented Apr 16, 2025

It looks to me like “the .keycode attribute” could be replaced by “event.key” -- but that is not an ambitious fix.

IMO the minimal and least controversial viable fix would be just ".keyCode property" instead of ".keycode attribute". Just for accuracy. It can still be found in the wild, and it probably still works. It's anachronistic alright, but then, event handling nowadays is usually buried under a thick layer of "normalization" by libraries or frameworks. I doubt that this kind of code search is useful with eventTarget abstractions.

Using event as an identifier without full context in documentation examples is historically burdened and should be used with caution. Internet Explorer thought it would be cute to have a global event object without passing it into a handler function or method, and its lifeline was extended via the original Opera to present day Chromium.

Fun!

event // global object (if implemented; and property of the window object)

function handle_something(event) {
  event // function parameter shadows global object (if implemented)
}

function handle_something() {
  event // global object (if implemented), function parameter omitted or forgotten
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants