WebStorm中的JavaScript未导出元素警告

我不明白为什么我收到的element is not exported在WebStorm IDE中的this.errors行的以下JavaScript中this.errors

 function FooBar(userId, email) { if (!util.isString(userId) || !userId.length) { throw Error('FooBar(): requires a non-empty userId:String'); } if (this instanceof FooBar) { this.id = generateId(); this.userId = userId; this.email = email; this.curStep = WORKER_STEPS[0]; this.completed = false; this.failed = false; this.createDate = new Date(); this.errors = {}; for (let step of WORKER_STEPS) { this.errors[step] = 0; } } else { return new FooBar(userId, email); } } 

在这里输入图像说明

我知道我可以得到很多的赞扬,因为它超出了问题的范围。

但现在是切换到ES6的时候了。
所以我会给你更好的解决scheme(:

1)打开EcmaScript 6支持:

WS-ES6

2)切换到class以避免使用function巨大的老class级定义

把这个添加到js文件的顶部,它将使nodejs解释器提醒关于内存韭葱或不必要的variables定义等不错的function。

 /* jshint strict: true */ 'use strict'; 

这里是你的FooBar

 const _ = require('lodash'); class Entity { hasError() { return !_.isEmpty(this.errors); } addError(step, error) { this.errors[step] = error; } getErrors() { return this.errors; } } class FooBar extends Entity { constructor(userId, email, steps = []) { if (_.isEmpty(userId) || !_.isString(userId)) throw Error('FooBar(): requires a non-empty userId:String'); this.id = generateId(); this.userId = userId; this.email = email; this.curStep = _.first(steps); this.completed = false; this.failed = false; this.createDate = new Date(); this.errors = {}; } } 

用法:

 let fooBar = new FooBar( '1f049de1-b592-4f17-9a7d-3f2097477b23', 'somebody@gmail.com', WORKER_STEPS); fooBar.addError(0, "Something happen"); // or fooBarInstance.addError("Somewhere", "Something happen"); if(fooBar.hasError()) { console.error(fooBarInstance.getErrors()); }