2016-09-20 4 views
1

WebStorm IDEで行にelement is not exportedという文字列を受け取っている理由がわかりません。WebStormの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); 
    } 
} 

enter image description here

+0

ただ一つの質問、それはv.6.x.xをNodeJSのですか? – num8er

+0

それはES6をサポートすることを幸運! (; https://nodejs.org/en/blog/release/v4.0.0/ – num8er

答えて

1

私はそれが質問の範囲外だcuzの私は、多くのdownvotesを得ることができます知っています。

しかし、今度はES6に切り替える時です。
だから私はあなたに、より良い解決策をあげる(:

1)のECMAScript 6のサポートをオンにします。

WS-ES6

2)function

を使用して巨大な古い学校のクラス定義を避けるために class 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', 
      '[email protected]', 
      WORKER_STEPS); 

    fooBar.addError(0, "Something happen"); // or fooBarInstance.addError("Somewhere", "Something happen"); 

if(fooBar.hasError()) { 
    console.error(fooBarInstance.getErrors()); 
} 
+0

コードを更新しましたが、もう一度見ていただけますか?エラーは他のプロパティとどのように違うのか分かりません。 –

+0

@DanielKobeは私の更新された答えをチェックする – num8er

関連する問題