Closed
Bug 1439757
Opened 7 years ago
Closed 7 years ago
`event.repeat` does not work when declaring `event` as a function parameter for event listeners.
Categories
(Core :: DOM: Events, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 218415
People
(Reporter: iiimosley, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36
Steps to reproduce:
Set up an event listener on keydown events (jQuery). In keydown, set conditional statement to prevent keydown from repeating, using `event.repeat`.
let allKeys = ["q","w","e","r","t","y"];
$(document).on('keydown', function(){
for (let i=0;i<allKeys.length;i++) {
if (event.key == allKeys[i] && !event.repeat){
/// logic to executed on initial keypress matching key values in array
/// & not repeating due to the boolean value of !event.repeat (false)
}
}
});
Actual results:
In Firefox, I received no results from keydown event listener & the console read "ReferenceError: event is not defined". As to follow Firefox protocol, I reformatted the listener's logic by placing `event` within the functions parameters & placed a console.log for `event.repeat` in the listener function.
let allKeys = ["q","w","e","r","t","y"];
$(document).on('keydown', function(event){
console.log(event.repeat);
for (let i=0;i<allKeys.length;i++) {
if (event.key == allKeys[i] && !event.repeat){
/// logic to executed on initial keypress matching key values in array
/// & not repeating due to the boolean value of !event.repeat (false)
}
}
});
The console.log returned `undefined` & the conditional statement persisted to repeat function in lieu of `!event.repeat` being `undefined`
Expected results:
(In Chrome and Safari) having not declared `event` in the function parameters: the `console.log` returns an initial `false` & perpetual `true` with the repeating of the keydown & the conditional statement executes the nested logic once with `!event.repeat` filtering only the initial keydown.
let allKeys = ["q","w","e","r","t","y"];
$(document).on('keydown', function(){
console.log(event.repeat);
for (let i=0;i<allKeys.length;i++) {
if (event.key == allKeys[i] && !event.repeat){
/// logic to executed on initial keypress matching key values in array
/// & not repeating due to the boolean value of !event.repeat (false)
}
}
});
Updated•7 years ago
|
Component: Untriaged → DOM: Events
Product: Firefox → Core
event in global scope is an old IEism. Shouldn't be used.
But there is an existing bug to add that hack to Gecko too. Will be likely to be fixed soon.
Can't find now the right bug.
Updated•7 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•