Last active
December 25, 2015 00:39
-
-
Save sufianrhazi/6889655 to your computer and use it in GitHub Desktop.
.is() strawman
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
/*global IMVU:true*/ | |
var IMVU = IMVU || {}; | |
(function() { | |
IMVU.extendError = function extendError(baseErrorType, errorName) { | |
var errorClass = IMVU.createNamedFunction(errorName, function(message) { | |
this.name = errorName; | |
this.message = message; | |
this.__isa = Object.create(baseErrorType.prototype.__isa || null); | |
this.__isa[errorName] = true; | |
var stack = (new Error(message)).stack; | |
if (stack !== undefined) { | |
this.stack = this.toString() + '\n' + | |
stack.replace(/^Error(:[^\n]*)?\n/, ''); | |
} | |
}); | |
errorClass.prototype = Object.create(baseErrorType.prototype); | |
errorClass.prototype.constructor = errorClass; | |
errorClass.prototype.toString = function() { | |
if (this.message === undefined) { | |
return this.name; | |
} else { | |
return this.name + ': ' + this.message; | |
} | |
}; | |
errorClass.prototype.is = function (type) { | |
return !!this.__isa[type]; | |
}; | |
return errorClass; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment