Closed
Bug 308297
Opened 19 years ago
Closed 19 years ago
DOM methods can't have optional/default arguments in JS
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
INVALID
People
(Reporter: stryker330, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4 Some DOM methods are very convoluted and some arguments to those methods should be optional. Examples: addEventListener: useCapture argument should default to false cloneNode: argument should be default to false init*Event (initMouseEvent being by far the worst) much of the XPath DOM methods I'm sure there has to be an existing bug concerning this, but for the life of me I can't find it (searched "optional arg", "optional param", "default arg", "default param", and "not enough arg"). Closest entry I could find is bug 125497, but I'm not sure if that's related. However, the bug description says something very relevant to this subject: "optional parameters truly are useful: in our experience they are much more intuitive to JavaScript programmers than other solutions (passing null, or calling different functions), and they allow for some degree of method overloading" So why are there no optional/default parameters for DOM methods? Is it a technical limitation? Or is it because of a strict interpretation of the W3C specs? If it's the latter, then why are JS functions valid EventListener's when an EventListener is supposed to be an object containing a handleEvent method? This seems very inconsistent to me in terms of JS convenience. Reproducible: Always Steps to Reproduce:
Comment 1•19 years ago
|
||
(In reply to comment #0) > So why are there no optional/default parameters for DOM methods? Is it a > technical limitation? Or is it because of a strict interpretation of the W3C > specs? The latter. > If it's the latter, then why are JS functions valid EventListener's when > an EventListener is supposed to be an object containing a handleEvent method? Because that's what the DOM Spec specifies in the EcmaScript binding. See http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/ecma-script-binding.html I vote for WONTFIX.
Comment 2•19 years ago
|
||
The DOM is a standard and we follow it. It does not specify any optional arguments.
JS functions are valid event listeners because the DOM spec says the following:
Object EventListener
This is an ECMAScript function reference. This method has no return value.
The parameter is a Event object.
I suspect this is INVALID or WONTFIX| Reporter | ||
Comment 3•19 years ago
|
||
Alright, I understand strictly following the spec and I now see the EventListener JS binding, though I still disagree with the strictness. IMO there should be the following set of rules for a JS binding to the DOM: 1) a JS function implements any interface that contains a single method and only that method 2) any interface that has a method that accepts an array index and only one such method should be indexable via the bracket notation (e.g. NodeList objects can already by indexed) 3) arguments that accept values of false, null, or "" should be optional unless there is a later argument that doesn't accept those values 4) a group of properties that function as a pseudo-union (only one property has a meaningful value at a time) should somehow be condensed into a single property for JS
Comment 4•19 years ago
|
||
(In reply to comment #3) > IMO there should be the following set of rules for a JS binding to the DOM: It's not up to us to decide on a set of rules for a JS binding to the DOM. The W3C have already defined a JS binding to the DOM and that is the standard that all browsers should work to.
| Reporter | ||
Updated•19 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
Updated•13 years ago
|
Assignee: general → nobody
OS: Windows XP → All
QA Contact: ian → general
Hardware: x86 → All
| Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•