2017-03-10 20 views
0

おそらく私は何か間違っています(拡張実装について間違った考え方をしています)が、elasticsearch.Client(https://github.com/elastic/elasticsearch-js/issues/516)クラスを拡張するメソッドを追加できないのはなぜですか?Es6のelasticSearchクラスを拡張していません

class MyClass extends elasticsearch.Client { 

    constructor(config) { 
     super(config);  

     this.testConnection(); //-> gives an this.testConnection is undefined 
    } 

    testConnection() { 
     this.ping({ 
      requestTimeout: 30000, 
     }, (error) => { 
      if(error) console.error('Elastic search is out'); 
      if(!error) { 
       console.log('Conected'); 
      } 
     }); 
    } 
} 

const client = new MyClass({ 
    host: 'my_host', 
    log: 'info' 
}); 

MyClass.testConnection(); //also an "undefined" error 

シモンズ:私は、私は彼らからの回答を得たメッセージ

+0

ソースコードで判断すると、クライアントはES6を使って書かれていません。同じことを達成したい場合は、クライアントを要求し、そのクライアントの機能にプロパティを追加して、再度エクスポートすることができます。 – ryanlutgen

+0

@ryanlutgen Typescriptで書かれています。それが問題だろうか? –

+0

プロジェクトはTypeScriptですか?ブラウザでコードを実行しようとしていますか(TSを使用している場合は、そのように仮定します)。自分のクライアント(https://github.com/elastic/elasticsearch-js/blob/master/src/lib/client.js)を必要とするクライアントを要求し、それが動作するかどうかをオブジェクトに追加するという私の提案を試すことができます。関連するすべてのコードを取得するには、webpackのようなビルドツールが必要です。 – ryanlutgen

答えて

関連する問題