wrong at least two things for the non ES6 version

 1. `Error.call(this, message)` does not do what you think it should do
 2. `CustomError.prototype = Object.create(Error)` has a typo, you meant `
Object.create(Error.prototype)`

In the ES6 version, I am not sure about constructors and classes, but name
should be inherited or the console won't even look for it as own property
so it should be

```javascript
class CustomError extends Error {
  name = 'CustomError'
  constructor (message /* accept any custom arguments here */) {
    super(message)
  }
}
```
only in case CustomError won't have already a `name` property as it is for
ES3<=ES5 constructors.

:-)




On Wed, Jul 10, 2013 at 4:22 PM, Forbes Lindesay <[email protected]>wrote:

> What's wrong with:
>
> ```javascript
>
> throw new CustomError('message')
>
> function CustomError(message /* accept any custom arguments here */) {
>   Error.call(this, message)
>   this.name = 'CustomError'
>   /**
>    * add any custom error info here
>    */
> }
> CustomError.prototype = Object.create(Error)
> CustomError.prototype.constructor = CustomError
> ```
>
> In ES6 land this becomes:
>
>
> ```javascript
>
> throw new CustomError('message')
>
> class CustomError extends Error {
>   constructor (message /* accept any custom arguments here */) {
>     super(message)
>     this.name = 'CustomError'
>
>     /**
>      * add any custom error info here
>      */
>   }
> }
> ```
>
> Doesn't that seem like an obvious enough solution?
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to