# Allow modifying class methods/properties in plugin-api?

**URL:** https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270
**Category:** Development
**Created:** [March 31, 2018, 2:38am UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270 "2018-03-31T02:38:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![shoshber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shoshber/32/95393_2.png) [@shoshber](https://meta.discourse.org/u/shoshber)
#### Post date: [March 31, 2018, 2:38am UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/1 "2018-03-31T02:38:55Z")

</div>

`plugin-api.modifyClass` allows us to overwrite instance methods of existing classes, but there is no analogous way to overwrite class methods. It would be cool if there were.

In my case, I want to overwrite the `user` model’s `createAccount` method ([discourse/app/assets/javascripts/discourse/models/user.js.es6 at 9df7fd4f308e007e4aa2cd17e40cee92b68fad07 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/9df7fd4f308e007e4aa2cd17e40cee92b68fad07/app/assets/javascripts/discourse/models/user.js.es6#L624)).

I got around it with this, drawing heavily on `plugin-api.modifyClass` …

```plaintext
const klass = api.container.factoryFor('model:user');

klass.class.reopenClass({
  createAccount(attrs) {
    console.log('overwrites createAccount')
  }
})  

```

… which seems to work, but it’s a little kludgy.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 3, 2018, 2:23am UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/2 "2018-04-03T02:23:28Z")

</div>

@eviltrout thoughts? I think adding `reopenClass` or something like that in plugin api makes sense, not sure what the right naming here is though.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [April 3, 2018, 1:55pm UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/3 "2018-04-03T13:55:35Z")

</div>

Sure `reopenClass` would be a good addition to the plugin api if you want to submit a PR @shoshber

---

<div class="post-metadata">

### Author: ![shoshber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shoshber/32/95393_2.png) [@shoshber](https://meta.discourse.org/u/shoshber)
#### Post date: [April 10, 2018, 11:40pm UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/4 "2018-04-10T23:40:22Z")

</div>

Ok, I will do that! 😀

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 9, 2018, 10:57pm UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/5 "2018-12-09T22:57:51Z")

</div>

Quick update … we now have `modifyClassStatic` thanks to @shoshber

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 9, 2018, 10:57pm UTC](https://meta.discourse.org/t/allow-modifying-class-methods-properties-in-plugin-api/84270/6 "2018-12-09T22:57:55Z")

</div>


