Last active
August 29, 2015 14:26
-
-
Save japboy/5b1feeb72126ee6b885c to your computer and use it in GitHub Desktop.
My subclass for Error class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
global = global or window | |
### | |
Subclass for Error | |
@class | |
@extends global.Error | |
@see http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript | |
@see https://gist.github.com/xdissent/d20bbdd57ca16b3d86b5 | |
### | |
class exports.Error | |
constructor: (message) -> | |
@name = @constructor.name | |
@message = message | |
@stack = (new global.Error).stack | |
@:: = new global.Error | |
@::constructor = @ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let global = global || window; | |
/** | |
* Subclass for Error | |
* @class | |
* @extends global.Error | |
* @see http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript | |
* @see https://gist.github.com/xdissent/d20bbdd57ca16b3d86b5 | |
*/ | |
export class Error extends global.Error { | |
constructor (message) { | |
this.name = this.constructor.name; | |
this.message = message; | |
this.stack = (new global.Error).stack | |
} | |
this.prototype = new global.Error; | |
this.prototype.constructor = this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment