Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom constructors #4

Open
yanickrochon opened this issue Mar 15, 2015 · 0 comments
Open

Custom constructors #4

yanickrochon opened this issue Mar 15, 2015 · 0 comments

Comments

@yanickrochon
Copy link
Owner

Instead of passing an Object, it should be possible to pass a function that would act as a custom constructor. This custom constructor would be invoked before calling the base prototype and, therefore, before generating the stack trace.

Note: the Error object constructor uses this.message to generate the stack trace, therefore the message content must be set beforehand.

When using a custom constructor, this._super is provided to invoke the base type constructor, event Error itself.

For example :

var BaseError = errorFactory('BaseError', ...);
var CustomError = errorFactory('CustomError', function (message, status) {
   this.status = status || 400;

   this._super(message);

   // ex: invoke some event listener
}, BaseError);

Note: this._super(...) or this.base(...) ?

Internally, the base type constructor is invoked as

function _super() {
  baseType.apply(this, arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant