Skip to content

Instantly share code, notes, and snippets.

@fatso83
Created September 10, 2018 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatso83/e199f4a93bc5d9436f103db401d9a691 to your computer and use it in GitHub Desktop.
Save fatso83/e199f4a93bc5d9436f103db401d9a691 to your computer and use it in GitHub Desktop.
$ 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