-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing documentation or bad implementation for util.isObject #743
Comments
It checks EDIT: I think "strictly" is thrown in there because |
yeah, the wording is really confusing |
Would this work for you:
|
Kinda, but it's generally a bad sign when the documentation basically rephrases the source code. It would be better to change the implementation to check whether Type(arg) is Object, to be consistent with the other |
The implementation does check whether |
(Util is frozen, I note, so doc change it'll have to be.) |
@ceejbot it's not about util being frozen, but about semver. Bumping major version because of |
The documentation for |
I do not think that the expected behavior for everyone is to return true for functions. There is |
It's the expected behavior for anyone who knows what an object is.
That's what |
This fixes issue nodejs#743. Brought the behavior of util.isObject() in line with expected behavior, inspired by utility libraries like underscore & lodash. In particular, it now returns true for functions, as expected. Added eight tests for isObject() to ensure it behaves as expected for a wide variety of input, including cases where it is expected to return false.
IMO the docs should change to explain that an Object is anything that isn't a primitive. Though that probably doesn't clear up a lot. |
Proposed functionality fix containing prior discussion: nodejs#822 Fixes: nodejs#743 PR-URL: nodejs#1295 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Brendan Ashworth <[email protected]>
Fixed by a doc fix in 245ba1d See later comments in #822 (comment) for doc vs functionality part. |
The documentation for
util.isObject
states:What exactly does "strictly an Object" mean? That the type of the argument is Object? Nope:
Or maybe it does an
instanceof
check? That also isn't the case:Does it check that the [[Class]] internal property is "Object"? Also no:
Either the docs should be updated to clarify the behavior, or the implementation should be fixed. I would vote for the latter, otherwise the function name is confusing.
The text was updated successfully, but these errors were encountered: