Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
10 changes: 10 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,18 @@ exports.log = function() {
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
* @throws {TypeError} Will error if either constructor is null, or if
* the super constructor lacks a prototype.
*/
exports.inherits = function(ctor, superCtor) {

if (isNullOrUndefined(ctor))

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.

In the codebase, the util.isXXX() functions have been phased out since 6ac8bdc, could you change them here and below to an inline alternative?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done so

throw new TypeError('The constructor to `inherits` must not be null.');
if (isNullOrUndefined(superCtor))
throw new TypeError('The super constructor to `inherits` must not be null.');

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.

This line is over 80 lines (make jslint), could you somehow fix that?

if (isUndefined(superCtor.prototype))
throw new TypeError('The super constructor must have a prototype.');

ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ assert.deepEqual(util._extend({a:1}, true), {a:1});
assert.deepEqual(util._extend({a:1}, false), {a:1});
assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});
assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});

// inherits
var ctor = function() {};
assert.throws(function() { util.inherits(ctor, {}) }, TypeError);
assert.throws(function() { util.inherits(ctor, null) }, TypeError);
assert.throws(function() { util.inherits(null, ctor) }, TypeError);
assert.doesNotThrow(function() { util.inherits(ctor, ctor) }, TypeError);