create-error.js简单的助手类库
create-error.js 是一个简单的助手类库,用于创建 Javascript 错误的之类。
Use:
$ npm install create-error $ bower install create-error
var createError = require('create-error'); var MyCustomError = createError('MyCustomError'); var SubCustomError = createError(MyCustomError, 'CoolSubError', {messages: []}); var sub = new SubCustomError('My Message', {someVal: 'value'}); sub instanceof SubCustomError // true sub instanceof MyCustomError // true sub instanceof Error // true assert.deepEqual(sub.messages, []) // true assert.equal(sub.someVal, 'value') // true
评论