原型覆盖类中的Access属性

问题描述 投票:0回答:1

不确定我的问题用词是否正确。但是基本上我有一个类,但是我想为其编写一个新方法。说我的班级看起来像这样:

class MyClass {
  constructor () {
    this.someProperty = []

    this.someMethod = this.someMethod.bind(this)
  }

  function someMethod () {
    // do something
  }
}

现在,因为我没有直接访问此类的权限,所以我将使用prototype创建一个新方法>

MyClass.prototype.myNewMethod = function (params) {
  // do something else
  // how to access someProperty? And to the bind to MyClass?
}

但是现在说我想访问someProperty,并且也想对此新方法进行bind。我该怎么办?

事实上,我的方法创建一开始就正确吗?无论如何,我想要它具有对类内部的this的相同访问权限。我该怎么办?

不确定我的问题用词是否正确。但是基本上我有一个类,但是我想为其编写一个新方法。说我的班级是这样的:class MyClass {Constructor(){this ....

javascript class prototype prototype-programming
1个回答
-1
投票

我不知道您想做什么,但是您可以访问它:

© www.soinside.com 2019 - 2024. All rights reserved.