Re: Handling too few arguments in method calls

Cameron McCormack:
> > From some very brief testing, it seems that Firefox and Opera tend
> > to throw an exception when calling a method with too few arguments,
> > while IE, Safari and Chrome will assume that the missing arguments
> > were the undefined value.

Simon Pieters:
> Hmm. What did you use as test case?

I did calls like:

  HTMLCollection.item()
  HTMLCollection.namedItem()
  HTMLDocument.getElementsByName()
  HTMLDocument.getElementsByClassName()
  Document.getElementById()
  Document.createTextNode()

making sure I could distinguish between that behviour and the behaviour
I’d get if calling with (undefined).

> I think I prefer option 2. It's easier for authors to find their mistake. 
> If a spec author wants the behavior of option 1, then that's possible 
> with [Optional].

I tend to prefer option 2, as well, for those reasons, plus it might
help us if we introduce new overloadeded operations later.  For example,
if we had

  interface A {
    /* f1 */ void f();
    /* f2 */ void f(in boolean x, in boolean y, in boolean z);
  };

and authors were calling A.f(something) and getting f2, then it might
make it harder for us to introduce

  void f(in boolean w);

or even

  void f(in DOMString w);

later on.

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Thursday, 25 June 2009 07:28:23 UTC