| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b2b0645 commit 7f5bb9d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,7 +132,10 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { | |||
| 132 | 132 | var keys = Object.keys(Console.prototype); | |
| 133 | 133 | for (var v = 0; v < keys.length; v++) { | |
| 134 | 134 | var k = keys[v]; | |
| 135 | - this[k] = Console.prototype[k].bind(this); | ||
| 135 | + // We have to bind the methods grabbed from the instance instead of from | ||
| 136 | + // the prototype so that users extending the Console can override them | ||
| 137 | + // from the prototype chain of the subclass. | ||
| 138 | + this[k] = this[k].bind(this); | ||
| 136 | 139 | } | |
| 137 | 140 | } | |
| 138 | 141 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,10 +105,16 @@ out.write = err.write = (d) => {}; | |||
| 105 | 105 | { | |
| 106 | 106 | class MyConsole extends Console { | |
| 107 | 107 | hello() {} | |
| 108 | + // See if the methods on Console.prototype are overridable. | ||
| 109 | + log() { return 'overridden'; } | ||
| 108 | 110 | } | |
| 109 | 111 | const myConsole = new MyConsole(process.stdout); | |
| 110 | 112 | assert.strictEqual(typeof myConsole.hello, 'function'); | |
| 111 | 113 | assert.ok(myConsole instanceof Console); | |
| 114 | + assert.strictEqual(myConsole.log(), 'overridden'); | ||
| 115 | + | ||
| 116 | + const log = myConsole.log; | ||
| 117 | + assert.strictEqual(log(), 'overridden'); | ||
| 112 | 118 | } | |
| 113 | 119 | ||
| 114 | 120 | // Instance that does not ignore the stream errors. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments