ES派生类的prototype方法中,不能访问super的解决方案

1 下面的B.prototype.compile方法中,无法访问super

class A {
  compile() {
    console.log('A')
  }
}

class B extends A {
  compile() {
    super.compile()
    console.log('B')
  }
}

B.prototype.compile = function() {
  super.compile() // 报错,不可以在此处使用super
  console.log('B2')
} 

const b = new B()
b.compile() // A B2

2 替代方法如下

class A {
  compile() {
    console.log('A')
  }
}

class B extends A {
  compile() {
    super.compile()
    console.log('B')
  }
}

B.prototype.compile = function() {
  A.prototype.compile.call(this) // 替代super
  console.log('B2')
} 

const b = new B()
b.compile() 

// A 
// B2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果 Elasticsearch 服务已经启动,但是在页面无法访问,可能是以下原因导致的: 1. Elasticsearch 服务监听的端口号不正确。默认情况下,Elasticsearch 服务监听的端口号为 9200。可以尝试使用以下命令检查 Elasticsearch 是否正在监听该端口: ``` curl http://localhost:9200/ ``` 如果返回类似下面的信息,则表示 Elasticsearch 服务已经正常启动: ``` { "name" : "node-1", "cluster_name" : "elasticsearch", "cluster_uuid" : "iCdI3tTXTwOe1F1xR8R5TQ", "version" : { "number" : "7.9.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "d34da0ea4a966c4e49417f2da2f244e3e97b4e6e", "build_date" : "2020-09-23T00:45:33.626720Z", "build_snapshot" : false, "lucene_version" : "8.6.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` 2. 防火墙或其他安全设置阻止了访问 Elasticsearch 服务。可以尝试在 Elasticsearch 所在的机器上或者访问 Elasticsearch 的机器上关闭防火墙或者修改相应的设置。 3. Elasticsearch 配置了安全认证,需要在请求提供相应的认证信息。可以参考 Elasticsearch 的官方文档,了解如何在请求提供安全认证信息。 4. Elasticsearch 配置了跨域资源共享(CORS)限制,需要在 Elasticsearch 的配置文件添加相应的设置。可以参考 Elasticsearch 的官方文档,了解如何配置 CORS。 如果以上方法都无法解决问题,可以在 Elasticsearch 的日志文件查找更详细的错误信息,或者在 Elasticsearch 官方论坛上提问寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值