Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get superclass name in ES6

I have a class, and another class that extends that class.

class Shape {
  constructor() {
    return this;
  }
}
class Circle extends Shape {
  constructor() {
    super();
    return this;
  }
}
let foo = new Circle();

I can get foo's class with

let className = foo.constructor.name 
// returns string 'Circle'

Is it possible to get the name of foo's superclass ('Shape') in a similar manner?

like image 656
joelg Avatar asked Jan 03 '16 01:01

joelg


1 Answers

Object.getPrototypeOf(Object.getPrototypeOf(foo)).constructor.name;
like image 169
dmx Avatar answered Oct 22 '22 07:10

dmx