Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ function isRegExp(re) {
exports.isRegExp = isRegExp;

function isObject(arg) {
return arg !== null && typeof arg === 'object';
var type = typeof arg;
return type === 'function' || type === 'object' && !!arg;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might still be faster to do arg !== null.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't change the behavior, so if it's faster, happy to make the change.

}
exports.isObject = isObject;

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ assert.equal(true, util.isError(Object.create(Error.prototype)));

// isObject
assert.ok(util.isObject({}) === true);
assert.ok(util.isObject(function() {}) === true);
assert.ok(util.isObject([1, 2, 3]) === true);
assert.ok(util.isObject(new String('string')) === true);
assert.ok(util.isObject(null) === false);
assert.ok(util.isObject(undefined) === false);
assert.ok(util.isObject('string') === false);
assert.ok(util.isObject(42) === false);
assert.ok(util.isObject(true) === false);

// isPrimitive
assert.equal(false, util.isPrimitive({}));
Expand Down