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.
Return value documentation errors
Re: Return value documentation errors
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
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
Re: Return value documentation errors
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
}
Re: Return value documentation errors
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.
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.
Re: Return value documentation errors
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.
Re: Return value documentation errors
We fixed the documentation issues. Again, thank you for reporting.
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
Return to “SFS2X HTML5 / JavaScript API”
Who is online
Users browsing this forum: No registered users and 29 guests