Skip to content

Instantly share code, notes, and snippets.

@sufianrhazi
Last active December 25, 2015 00:39
Show Gist options
  • Save sufianrhazi/6889655 to your computer and use it in GitHub Desktop.
Save sufianrhazi/6889655 to your computer and use it in GitHub Desktop.
.is() strawman
/*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