From 04a291abec3b86ed902c5e9919b2a8adf1e07d14 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 3 Nov 2018 03:20:23 +0800 Subject: console: bind methods from the prototype chain in Console In 62232361 we made the console.Console function construct an object with methods from Console.prototype bound to the instance, instead of with methods found on the prototype chain to be bound on the instances, thus breaking users overriding these methods when subclassing Console because they are not expecting this function to construct a namespace whose methods are not looked up from the prototype chain. This patch restores the previous behavior since it does not affect the characteristics of the global console anyway. So after this patch, the Console function still constructs normal objects with function properties looked up from the prototype chain but bound to the instances always. PR-URL: https://github.com/nodejs/node/pull/24047 Reviewed-By: John-David Dalton Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- lib/console.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/console.js') diff --git a/lib/console.js b/lib/console.js index 2e56f7bbba..39e55c202c 100644 --- a/lib/console.js +++ b/lib/console.js @@ -129,7 +129,10 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { var keys = Object.keys(Console.prototype); for (var v = 0; v < keys.length; v++) { var k = keys[v]; - this[k] = Console.prototype[k].bind(this); + // We have to bind the methods grabbed from the instance instead of from + // the prototype so that users extending the Console can override them + // from the prototype chain of the subclass. + this[k] = this[k].bind(this); } } -- cgit v1.2.3