title: Knockout JS Calling a ViewModel function inside a foreach binding
body: <p>Let's consider a view model using knockout like that:</p>
  
  <pre><code>var data = [{ id: 1, name: "John Doe" }, { id: 2, name: ""}, { id: 3, name: "Peter Parker"}];
  
  var viewModel = {
      items: ko.observableArray(data)
  };
  
  viewModel.showName = function (name) {
      console.log(this);
      return name &amp;&amp; name.length &gt; 0;
  };
  
  viewModel.removePerson = function () {
      console.log(this); 
  };
  
  ko.applyBindings(viewModel);
  </code></pre>
  
  <p>With this View:</p>
  
  <pre><code>&lt;ul data-bind="foreach: items"&gt;
      &lt;li&gt;&lt;span data-bind="text: id"&gt;&lt;/span&gt;
           &lt;span data-bind="visible: $root.showName(name)"&gt;Yes! show the name&lt;/span&gt;
           &lt;a href="#" data-bind="click: $root.removePerson"&gt;Remove&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>You can see it in action here: <a href="http://jsfiddle.net/SmW35/8/" rel="noreferrer">http://jsfiddle.net/SmW35/8/</a></p>
  
  <p>In this case, when someone clicks the "Remove" link, and KO calls the showName function,
  the object "this" inside the function, it's an object with the current item, for example, if I click "remove" in the item 2, "this" is {id: 2, name: ""}
  However, when KO is binding the "visible" and calls the showName function, the "this" object doesn't contains the current item, and you have to pass "name" to the function (or you could use the $data).</p>
  
  <p>So, I have 2 questions:</p>
  
  <ul>
  <li>There's a way to call the showName function from the View, without passing the name or $data (similar behaviour than with the Remove link)</li>
  <li>If not, there's something wrong do it that way? I have an interesting discussion with a workmate that thinks that is not right do it that way because you are sending data from the View ($root.showName(name)), and then this is not a "pure" MVVM pattern. He's proposing create a custom KO binding to achieve the functionality. In my opinion is killing flies with a tank, but I'm very curious to know if there's a different way or you also think I'm not doing a pure MVVM pattern with my code.</li>
  </ul>