Fixing up AssertionError inheritance.

* Use `Object.create` instead of `__proto__` for inheritance.
* Don't forget to set `AssertionError.prototype.constructor`.
* Put `name` on `AssertionError.prototype`, not on each instance.
This commit is contained in:
domenic 2012-04-14 22:55:10 -04:00
parent e7d89e24dd
commit 272fcf5a3c
2 changed files with 6 additions and 4 deletions

View file

@ -8,7 +8,6 @@ module.exports = AssertionError;
function AssertionError (options) {
options = options || {};
this.name = 'AssertionError';
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
@ -20,7 +19,9 @@ function AssertionError (options) {
}
}
AssertionError.prototype.__proto__ = Error.prototype;
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = 'AssertionError';
AssertionError.prototype.constructor = AssertionError;
AssertionError.prototype.toString = function() {
return this.message;

View file

@ -35,7 +35,6 @@ module.exports = AssertionError;
function AssertionError (options) {
options = options || {};
this.name = 'AssertionError';
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
@ -80,7 +79,9 @@ function AssertionError (options) {
* Inherit from Error
*/
AssertionError.prototype.__proto__ = Error.prototype;
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = 'AssertionError';
AssertionError.prototype.constructor = AssertionError;
/**
* # toString()