Closed
Bug 275306
Opened 20 years ago
Closed 20 years ago
javascript: eventhandler assignment with "with()"
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 159849
People
(Reporter: bugzilla.mozilla.org, Unassigned)
References
()
Details
when i do not misinterpret the Object Model of javascript the following things
should do the same:
obj = some_input_htmlnode
function test(){alert(this)}
with(obj)
{
onkeyup = test
}
and
obj.onkeyup = test
but the 1st variant returns the window-object and the second the html-node
Comment 1•20 years ago
|
||
You have in the url in the function this code:
obj = document.getElementById("test");
with(obj) {onkeyup = test}
obj.onkeyup = test
so the first onkeyup gets overwritten by the second.
You simply get two keyup events when the input is focused, one for the input and
one for the window.
When the input is not focused, you only get the event for the window.
I think this is INVALID.
Product: Firefox → Core
(In reply to comment #1)
> When the input is not focused, you only get the event for the window.
>
> I think this is INVALID.
Well, i figured that out already. It seems so that the implicit onkeyup of the
window-element (which is owner of all userdefined functions) has higher
precedence than the onkeyup of the object that is used with the with()
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
If I interpret the chapter about the with() correctly (page 79) all propertys of
the object should be within the current scope and so overrule the implicit
propertys of the window-object.
But i might be wrong...
Comment 3•20 years ago
|
||
Unqualified names within a |with| statement only match existing properties, they
won't create new ones. If you check the result of |"onkeyup" in obj| before and
after |with| you'll see it is false in both cases.
Assignee: bugs → general
Component: JavaScript Console → DOM: Level 0
QA Contact: firefox.js-console → ian
(In reply to comment #3)
> Unqualified names within a |with| statement only match existing properties
well a with(obj){tabIndex = 10} works on an unset tabindex
according to the DTD for XHTML1.0 Strict both attributes are #IMPLIED (and when
not set: empty). And still... the window-object's onkeyup should be undefined
too, since the with creates a local scope the property should either be created
or the variable onkeyup should cease to exist after the with()-Block.
Comment 5•20 years ago
|
||
|with| does not create a local scope, it adds an object to the front of the
scope chain. The following script:
with (Math) { abc=15; }
sets the global object's abc property to 15, just like your code sets the global
object's onkeyup property to test.
onkeyup (or any other event) is not defined as a property of HTMLInputElement in
DOM HTML or DOM Events; tabIndex is, that's why you can set it unqualified in a
with block.
However, your code works in IE and it may be desirable to be compatible here. Do
you know any website that is affected by this?
ah, now I understand. I misinterpreted the definition of with() and since it
worked in Opera (and IE too as you said) i thought it is a bug in the
Javascript-Engine.
Well, maybe the eventhandlers are internally predefind with "null" in IE or
Opera... have to check this.
And no, I don't know any site affected, i was just developing a little tool in
javascript and tried to save some typing with with()
Since with() is rarely used I think there is no need for compatibility with IE.
It's just an counter-intuitive part of the JavaScript... which is correctly
implemented by Mozilla.
A standardscompliant way would be (would it?) to define every property of
HTMLnodes with null-pointers i.e.
But I think thats to much efford for such a tiny bit of code... and could lead
to other Bugs.
Well... we can just forget about it... silly dumb me :(
Comment 7•20 years ago
|
||
*** This bug has been marked as a duplicate of 159849 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•