Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Binding vs EventBinding: this context differs when bound to a function

$
0
0

I noticed such a behavior of, let's say, "common" (e. g., "enabled") binding and event binding: when bound to a function this context differs inside it.

For example, I add 2 functions to ObservableArray's prototope:

1) logTihis: simply logs this pointer to the console

console.log(this);

2) enableDelete: returns whether the array has more than 1 items (assume, I want to prevent deletion of the last item)

returnthis.length > 1;

and a template to render repeating items ("items" field of the view model is set to an array):

<tr>
  <td>#= name #</td>
  <td><buttondata-role="button"data-bind="enabled: parent().enableDelete, click: parent().logThis">Delete</button>
</tr>

When I write "parent().functionName" I expect the function to be called in the context of what parent() returns (items array in this case).

With enabed binding it is so (having 1 item in the array disables the button), while with click binding it is not so (this pointer in the click handler (logThis) is set to the item itself).

After checking the source code I found out that Binding.get does look for the actual context before calling the function while EventBinding.get does not.

Why is it so? Is not it about to be fixed?

 

Thank you in advance.


Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>