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: Wed, 23 Oct 2013 21:20:36 +0000
To: public-script-coord@w3.org
Message-ID: <bug-23532-3890-r2qSImLR4T@http.www.w3.org/Bugs/Public/>
https://www.w3.org/Bugs/Public/show_bug.cgi?id=23532

--- Comment #23 from Allen Wirfs-Brock <allen@wirfs-brock.com> ---
(In reply to Jonas Sicking from comment #21)
> If the goal is "treat passing undefined the same as not passing the argument
> at all, even for non-optional arguments", then we actually have two options:
> 
> For a function like "void func(double arg)"
> 
> A) Make both func() and func(undefined) throw TypeError.
> B) Make both func() and func(undefined) be equivalent to
>    func(ToNumber(undefined)), i.e. equivalent to func(NaN).
> 
> So far we've mostly debated A, which doesn't seem very web compatible.
> 
> We certainly could do A for any new functions added to the platform, however
> that would create inconsistency between old and new functions which is
> unfortunate.
> 
> B is likely much more web compatible, and could probably be done for both
> old and new APIs. Not throwing also feels a lot more "javascripty", but
> that's obviously a matter of opinion.
> 
and B is exactly how a JS function defined as
   function func(aNumber) { return +aNumber}

would behave if called either as func() or func(undefined)

It what a JS programmer expects, if leave out a argument that is used as a 
number (or pass undefined) it will be treated as if it was NaN.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
Received on Wednesday, 23 October 2013 21:20:39 UTC

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