W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

[Bug 23532] Dealing with undefined

From: <bugzilla@jessica.w3.org>
Date: Thu, 24 Oct 2013 14:03:33 +0000
To: public-script-coord@w3.org
Message-ID: <bug-23532-3890-W0igSpGSRI@http.www.w3.org/Bugs/Public/>

--- Comment #30 from Erik Arvidsson <arv@chromium.org> ---
(In reply to Ms2ger from comment #29)
> If we want ES and DOM APIs to align, and the DOM APIs have clearly more
> useful behaviour, perhaps the ES APIs should change?

There is one big difference between DOM APIs and JS. In JS you need to write
functions that has optional parameters and calls other functions with optional
parameters. In DOM you only need to call functions.

If you use arguments.length for these you have to do a lot of boiler plate code
to cover all the options.

function g(x = undefined, y = undefined, z = undefined) {}

function f(x = undefined, y = undefined, z = undefined) {
  // do something
  switch (arguments.length) {
    case 0:
      return g();
    case 1:
      return g(x);
    case 2:
      return g(x, y);
      return g(x, y, z);

But using the semantics in ES6

function f(x = undefined, y = undefined, z = undefined) {
  // do something
  return g(x, y, z);

Also, whether WebIDL has a more useful behavior is debatable. I haven't seen
many (any?) JS libraries follow WebIDL.

You are receiving this mail because:
You are on the CC list for the bug.
Received on Thursday, 24 October 2013 14:03:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:18 UTC