SteveSanderson/knockout — Issue #244: 'this' inside event handlers
Author: nazjunaid
Created: 2011-12-22 15:24:11+00:00
State: open

We have been re-factoring some of our knockout code into knockout 2 but have noticed for some of the event handlers we cannot use the new style cleaner data-bind code because the "this" context is different to previous knockoutjs.

If we use knockout2 style of...
```
data-bind="click: $parent.myClickHandler"
```
Then In myClickHandler function context "this" refers to data and there doesn't seem to be an easy way to access the parent.

However if re-written as bellow...
```
data-bind="click: function(data, event) { $parent.myClickHandler(data, event) }"
```
"this" now refers to the viewModel.

It would be nice if we can still use this cleaner syntax instead of the work around if the changing of context was intentional and not a bug then will it be possible to have another default parameter which gives us access to the parent?