<h3 dir="auto">Input Code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function assert(holds, message) {
  if (!holds) {
    throw new Error(message || `Assertion does not hold`);
  }
}

class A {}
class FromA extends A {
  constructor(...args) {
    super(...args)
    assert(this.constructor.name === `FromA`, `the constructor of FromA should be &quot;FromA&quot; and is ${this.constructor.name}`);
  }
}

class FromError extends Error {
  constructor(...args) {
    super(...args)
    assert(this.constructor.name === `FromError`, `the constructor of FromError should be &quot;FromError&quot; and is ${this.constructor.name}`);
  }
}

const a = new FromA();
const e = new FromError();"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">assert</span><span class="pl-kos">(</span><span class="pl-s1">holds</span><span class="pl-kos">,</span> <span class="pl-s1">message</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">holds</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s1">message</span> <span class="pl-c1">||</span> <span class="pl-s">`Assertion does not hold`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-v">A</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">class</span> <span class="pl-v">FromA</span> <span class="pl-k">extends</span> <span class="pl-v">A</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span>
    <span class="pl-en">assert</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">===</span> <span class="pl-s">`FromA`</span><span class="pl-kos">,</span> <span class="pl-s">`the constructor of FromA should be "FromA" and is <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-v">FromError</span> <span class="pl-k">extends</span> <span class="pl-v">Error</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span>
    <span class="pl-en">assert</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">===</span> <span class="pl-s">`FromError`</span><span class="pl-kos">,</span> <span class="pl-s">`the constructor of FromError should be "FromError" and is <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">FromA</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">e</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">FromError</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><a href="https://babeljs.io/repl/#?babili=false&amp;evaluate=true&amp;lineWrap=false&amp;presets=es2015&amp;targets=&amp;browsers=&amp;builtIns=false&amp;code=function%20assert(holds%2C%20message)%20%7B%0A%20%20if%20(!holds)%20%7B%0A%20%20%20%20throw%20new%20Error(message%20%7C%7C%20%60Assertion%20does%20not%20hold%60)%3B%0A%20%20%7D%0A%7D%0A%0Aclass%20A%20%7B%7D%0Aclass%20FromA%20extends%20A%20%7B%0A%20%20constructor(...args)%20%7B%0A%20%20%20%20super(...args)%0A%20%20%20%20assert(this.constructor.name%20%3D%3D%3D%20%60FromA%60%2C%20%60the%20constructor%20of%20FromA%20should%20be%20%22FromA%22%20and%20is%20%24%7Bthis.constructor.name%7D%60)%3B%0A%20%20%7D%0A%7D%0A%0Aclass%20FromError%20extends%20Error%20%7B%0A%20%20constructor(...args)%20%7B%0A%20%20%20%20super(...args)%0A%20%20%20%20assert(this.constructor.name%20%3D%3D%3D%20%60FromError%60%2C%20%60the%20constructor%20of%20FromError%20should%20be%20%22FromError%22%20and%20is%20%24%7Bthis.constructor.name%7D%60)%3B%0A%20%20%7D%0A%7D%0A%0Aconst%20a%20%3D%20new%20FromA()%3B%0Aconst%20e%20%3D%20new%20FromError()%3B" rel="nofollow">REPL Link</a></p>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;presets&quot;: [
    &quot;es2015&quot;
  ]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span>
    <span class="pl-s">"es2015"</span>
  <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">When extending from <code class="notranslate">Error</code>, the new class's <code class="notranslate">this.constructor.name</code> should be the new class's name.</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">When extending from <code class="notranslate">Error</code>, the new class's <code class="notranslate">this.constructor.name</code> is <code class="notranslate">Error</code></p>
<h3 dir="auto">Context</h3>
<p dir="auto">I'm currently using <a href="https://github.com/ianwremmel/extend-error">https://github.com/ianwremmel/extend-error</a> (which has its own set of issues) to create subclassed Errors. Stringifying with the error name is very helpful for a debug process (in particular, subclassing for each http response code). In order to make that work, something like</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Exception extends Error {
  constructor(...args) {
    super(...args)
    this.name = `Exception`
  }
}
console.log(new Exception(`blarg`));"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Exception</span> <span class="pl-k">extends</span> <span class="pl-v">Error</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">=</span> <span class="pl-s">`Exception`</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Exception</span><span class="pl-kos">(</span><span class="pl-s">`blarg`</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">will produce <code class="notranslate">[Exception: blarg]</code>. Ideally, I would be able to use <code class="notranslate">this.name = this.constructor.name</code> instead of <code class="notranslate">this.name = \</code>Exception``.</p>
<h3 dir="auto">Your Environment</h3>
<p dir="auto">I've mostly been debugging this in the repl, but my local environment is:</p>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.22.1</td>
</tr>
<tr>
<td>node</td>
<td>7.2.0</td>
</tr>
<tr>
<td>npm</td>
<td>3.10.9</td>
</tr>
<tr>
<td>Operating System</td>
<td>macOs Sierra</td>
</tr>
</tbody>
</table>
<p dir="auto">index.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Exception extends Object { //Array, Number, String, Function, Error, RegExp, Boolean all of base type has this program
	constructor() {
		super('Exception');
	}
}
module.exports = Exception;"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Exception</span> <span class="pl-k">extends</span> <span class="pl-v">Object</span> <span class="pl-kos">{</span> <span class="pl-c">//Array, Number, String, Function, Error, RegExp, Boolean all of base type has this program</span>
	<span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
		<span class="pl-smi">super</span><span class="pl-kos">(</span><span class="pl-s">'Exception'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
	<span class="pl-kos">}</span>
<span class="pl-kos">}</span>
<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-v">Exception</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">gulpfile.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const gulp = require('gulp');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');

gulp.task('default', () =&gt; {
	browserify({
			entries: &quot;./index.js&quot;,
			standalone: 'Exception',
			debug: true
		})
		.transform(babelify.configure({
			presets: [&quot;es2015&quot;, &quot;stage-3&quot;],
			sourceMaps: true
		}))
		.bundle()
		.pipe(source('index.js'))
		.pipe(buffer())
		.pipe(gulp.dest('./dest'));
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">gulp</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'gulp'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">browserify</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'browserify'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">babelify</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'babelify'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">source</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'vinyl-source-stream'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">buffer</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'vinyl-buffer'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">gulp</span><span class="pl-kos">.</span><span class="pl-en">task</span><span class="pl-kos">(</span><span class="pl-s">'default'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
	<span class="pl-s1">browserify</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
			<span class="pl-c1">entries</span>: <span class="pl-s">"./index.js"</span><span class="pl-kos">,</span>
			<span class="pl-c1">standalone</span>: <span class="pl-s">'Exception'</span><span class="pl-kos">,</span>
			<span class="pl-c1">debug</span>: <span class="pl-c1">true</span>
		<span class="pl-kos">}</span><span class="pl-kos">)</span>
		<span class="pl-kos">.</span><span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-s1">babelify</span><span class="pl-kos">.</span><span class="pl-en">configure</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
			<span class="pl-c1">presets</span>: <span class="pl-kos">[</span><span class="pl-s">"es2015"</span><span class="pl-kos">,</span> <span class="pl-s">"stage-3"</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
			<span class="pl-c1">sourceMaps</span>: <span class="pl-c1">true</span>
		<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
		<span class="pl-kos">.</span><span class="pl-en">bundle</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
		<span class="pl-kos">.</span><span class="pl-en">pipe</span><span class="pl-kos">(</span><span class="pl-s1">source</span><span class="pl-kos">(</span><span class="pl-s">'index.js'</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
		<span class="pl-kos">.</span><span class="pl-en">pipe</span><span class="pl-kos">(</span><span class="pl-s1">buffer</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
		<span class="pl-kos">.</span><span class="pl-en">pipe</span><span class="pl-kos">(</span><span class="pl-s1">gulp</span><span class="pl-kos">.</span><span class="pl-en">dest</span><span class="pl-kos">(</span><span class="pl-s">'./dest'</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">test.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const Exception = require('./dest/index');

console.log(new Exception() instanceof Exception);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-v">Exception</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./dest/index'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Exception</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-k">instanceof</span> <span class="pl-v">Exception</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">the result is <code class="notranslate">false</code></p>
<p dir="auto">new Exception() is not instanceof Exception, but only instanceof Error</p>