Firefox ES6, Get Constructor Class Name

I'm having trouble getting the constructor name when using ES6 classes in Firefox. It works fine in Chromium, but does Firefox seem to have some kind of error? In Firefox, I get only an empty string. Anyone who knows about a workaround?

class MyClass {} let a = new MyClass(); console.log(a.constructor.name); 
+6
source share
1 answer

I think this is a mistake (according to the comment below).

It seems that specifying an explicit constructor shows the correct behavior in Firefox (even the latest version 48).

 class MyClassWithConstructor { constructor() { console.log("Explicit Constructor") } } class MyClassWithoutConstructor {} $('#with').click(function() { let tmp = new MyClassWithConstructor(); alert("MyClassWithConstructor name = " + tmp.constructor.name); }) $('#without').click(function() { let tmp = new MyClassWithoutConstructor(); alert("MyClassWithConstructor name = " + tmp.constructor.name); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id=with>With Constructor</button> <button id=without>Without Constructor</button> 

Here's a link to JSFiddle: https://jsfiddle.net/jc7g5crp/

+1
source

All Articles