可能我做错了(或者在扩展实现上得到了错误的想法),但为什么我不能添加扩展elasticsearch.Client(https://github.com/elastic/elasticsearch-js/issues/516)类的方法?
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
Ps:调用super方法,因为我有一个"弹性信息连接"消息