util: set super_
property to non-enumerable
Using `util.inherits()` adds a `super_` property to the constructor and inspecting that constructor is going to show that property even though it's not useful for the user. Therefore the property is now set as non-enumerable and such entries are not visible by default when using `console.log()` or `util.inspect()`. PR-URL: https://github.com/nodejs/node/pull/23107 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6df2c556bd
commit
5e6940d4f6
@ -285,7 +285,11 @@ function inherits(ctor, superCtor) {
|
||||
throw new ERR_INVALID_ARG_TYPE('superCtor.prototype',
|
||||
'Function', superCtor.prototype);
|
||||
}
|
||||
ctor.super_ = superCtor;
|
||||
Object.defineProperty(ctor, 'super_', {
|
||||
value: superCtor,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,15 @@ function B(value) {
|
||||
inherits(B, A);
|
||||
B.prototype.b = function() { return this._b; };
|
||||
|
||||
assert.strictEqual(B.super_, A);
|
||||
assert.deepStrictEqual(
|
||||
Object.getOwnPropertyDescriptor(B, 'super_'),
|
||||
{
|
||||
value: A,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
}
|
||||
);
|
||||
|
||||
const b = new B('b');
|
||||
assert.strictEqual(b.a(), 'a');
|
||||
|
Loading…
x
Reference in New Issue
Block a user