Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
元素未导出警告WebStorm中的JavaScript_Javascript_Node.js_Webstorm - Fatal编程技术网

元素未导出警告WebStorm中的JavaScript

元素未导出警告WebStorm中的JavaScript,javascript,node.js,webstorm,Javascript,Node.js,Webstorm,我不明白为什么我在WebStorm IDE的this.errors行收到以下JavaScript的元素未导出 function FooBar(userId, email) { if (!util.isString(userId) || !userId.length) { throw Error('FooBar(): requires a non-empty userId:String'); } if (this instanceof FooBar) { this.i

我不明白为什么我在WebStorm IDE的
this.errors
行收到以下JavaScript的
元素未导出

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的时候了。
所以我会给你更好的解决方案(:

1) 启用EcmaScript 6支持:

2) 切换到
es,以避免使用
函数定义大量老式类

将此添加到js文件的顶部,它将使nodejs解释器对内存不足或不必要的变量定义等特性发出警告

/* 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());
}

我更新了密码,你介意再看一眼吗。我不明白错误与其他属性有什么不同。只有一个问题,它是NodeJS v.6.x.x吗?幸运的是它支持ES6!(;