Created
September 10, 2018 21:11
-
-
Save fatso83/e199f4a93bc5d9436f103db401d9a691 to your computer and use it in GitHub Desktop.
This file contains 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
$ node | |
> class A{ constructor(){ console.log('A normal super class'); } } | |
undefined | |
> class B extends A{} | |
undefined | |
> new B | |
A normal super class | |
B {} | |
> sinon = require('sinon') | |
... | |
> Object.setPrototypeOf(B, sinon.stub().callsFake(function() { console.log('I am Super Stub!'); } )) | |
[Function: B] | |
> new B | |
I am Super Stub! | |
B {} | |
> Object.getPrototypeOf(B).callCount | |
1 | |
> new B && Object.getPrototypeOf(B).callCount | |
I am Super Stub! | |
2 | |
> Object.getPrototypeOf(B) === B.__proto__ | |
true | |
// now for some old school ES5 equivalents | |
> function C() { console.log('An old-skool super class'); } | |
undefined | |
> function D(){ C.call(this); } | |
undefined | |
> new D() | |
An old-skool super class | |
D {} | |
> D.prototype = Object.create(C.prototype) | |
C {} | |
> new D instanceof C | |
An old-skool super class | |
true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment