Last active
August 29, 2015 14:19
-
-
Save trevnorris/e3144f66dfa0aac6ff27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| class Readable { | |
| constructor() { | |
| this._onreadable = null; | |
| // Acquire the default onreadable callback if it's been set. | |
| if (typeof this.constructor._onreadable === 'function') | |
| this._onreadable = this.constructor._onreadable; | |
| } | |
| static onreadable(cb) { | |
| if (typeof cb !== 'function') | |
| throw new TypeError('callback must be a function'); | |
| this._onreadable = cb; | |
| } | |
| } | |
| Readable._onreadable = null; | |
| // Extending this | |
| class MyReadable extends Readable { | |
| constructor() { | |
| super(); | |
| } | |
| } | |
| // Don't want the internal Object Map to change, so still have to do this. | |
| MyReadable._onreadable = undefined; | |
| class MyReadable2 extends Readable { | |
| constructor() { | |
| super(); | |
| } | |
| } | |
| // Don't want the internal Object Map to change, so still have to do this? | |
| MyReadable2._onreadable = undefined; | |
| print(Object.keys(MyReadable)); | |
| Readable.onreadable(function foo() { }); | |
| MyReadable.onreadable(function bar() { }); | |
| MyReadable2.onreadable(function baz() { }); | |
| let r = new Readable(); | |
| //print(Readable._onreadable); // output: function foo() { } | |
| //print(r._onreadable); // output: function foo() { } | |
| let mr = new MyReadable(); | |
| //print(MyReadable._onreadable); // output: function bar() { } | |
| //print(mr._onreadable); // output: function bar() { } | |
| let mr2 = new MyReadable2(); | |
| //print(MyReadable2._onreadable); // output: function baz() { } | |
| //print(mr2._onreadable); // output: function baz() { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment