Return value documentation errors

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

User avatar
Rob
Posts: 34
Joined: 01 Jul 2017, 07:33

Return value documentation errors

Postby Rob » 02 Jul 2019, 08:14

There are several places in the documentation where functions are listed as returning null, when they in fact return undefined.
This will obviously cause bugs if a developer explicitly checks for null.

Examples are the getUserById & getUserByName functions.
User avatar
Lapo
Site Admin
Posts: 20959
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Return value documentation errors

Postby Lapo » 02 Jul 2019, 09:16

Hi,
I am not clear on the use case. What do you mean by "if a developer explicitly checks for null"?
Using the tripe equals operator (===) ?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Rob
Posts: 34
Joined: 01 Jul 2017, 07:33

Re: Return value documentation errors

Postby Rob » 02 Jul 2019, 13:19

While both null and undefined are falsy values in Javascript they are not the same. So if the developer assumes null is what indicates an error, something like this could happen:

Code: Select all

const usr = myRoom.getUserById(x);
if (usr === null) {
   // Handle error
} else {
   // Assume all is OK
}
User avatar
Lapo
Site Admin
Posts: 20959
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Return value documentation errors

Postby Lapo » 02 Jul 2019, 15:45

Sure, because null and undefined represent different states they don't "mean" the same thing, though in practical terms they do, most of the times.

We'll certainly fix that in the docs.
At the same time, since we're nitpicking, I am not sure why you would need to use the === operator (in that context) to check for a null value, where there is no ambiguity implied or declared.

I would expect the === to be useful where you need to distinguish between null and undefined. In those cases there is no such need. You either get an object, or you don't.

Regardless, thanks for reporting.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Rob
Posts: 34
Joined: 01 Jul 2017, 07:33

Re: Return value documentation errors

Postby Rob » 02 Jul 2019, 16:15

Yeah, I wouldn't use === like that. I would use something like if (!usr) { ... } it was just an example of what might happen with the current documentation.
User avatar
Bax
Site Admin
Posts: 4474
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Return value documentation errors

Postby Bax » 03 Jul 2019, 09:35

We fixed the documentation issues. Again, thank you for reporting.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 3 guests