# sendWidgetAction and Event not binding \`this\` to widget

**URL:** https://meta.discourse.org/t/sendwidgetaction-and-event-not-binding-this-to-widget/53285
**Category:** Development
**Created:** [11월 23, 2016, 4:57오전 UTC](https://meta.discourse.org/t/sendwidgetaction-and-event-not-binding-this-to-widget/53285 "2016-11-23T04:57:32Z")
**Posts on this page:** 2
**Page:** 1

<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: [11월 23, 2016, 4:57오전 UTC](https://meta.discourse.org/t/sendwidgetaction-and-event-not-binding-this-to-widget/53285/1 "2016-11-23T04:57:32Z")

</div>

This is mainly for @eviltrout but would have implications to all plugin devs.

At the moment `sendWidgetAction` and `Event` is not binding `this` to the widget.

```plaintext
sendWidgetAction(name, param) {
    return this.rerenderResult(() => {
      const widget = this._findAncestorWithProperty(name);
      if (widget) {
        return widget[name](param);
      }

      return this._sendComponentAction(name, param || this.findAncestorModel());
    });
  }

```

In particular we have

```plaintext
      if (widget) {
        return widget[name](param);
      }

```

Instead this could be:

```plaintext
     if (widget) {
        return widget[name].call(widget, param);
      }

```

Is there and reason we should not make this change?

---

<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: [11월 24, 2016, 3:59오후 UTC](https://meta.discourse.org/t/sendwidgetaction-and-event-not-binding-this-to-widget/53285/2 "2016-11-24T15:59:50Z")

</div>

This seems totally sensible to me. You’d expect a widget’s method to have `this` pointing to itself. I doubt there are any plugins that counted on `this` pointing at something else, and if so that’s confusing and they should be updated.

I’ve made the change:

[https://github.com/discourse/discourse/commit/66f68e8faf3fa466a431ebbff7af5c1c93b1c664](https://github.com/discourse/discourse/commit/66f68e8faf3fa466a431ebbff7af5c1c93b1c664)
