title: KnockoutJS - How do computed observables with conditional statements work
body: <p>KnockoutJS has the concept of computed observables, which are functions that depend on one or more observables. Knockout is able to <a href="http://knockoutjs.com/documentation/computedObservables.html" rel="noreferrer">determine the dependencies of a computed observable as described in the docs</a>:</p>
  
  <blockquote>
    <p>Whenever you declare a computed observable, KO immediately invokes its
    evaluator function to get its initial value. While your evaluator
    function is running, KO keeps a log of any observables (or computed
    observables) that your evaluator reads the value of.</p>
  </blockquote>
  
  <p>Now, what I don't understand is, how this works if your computed observable contains conditional logic. If Knockout invokes the evaluator function, surely conditional logic might result in observables which the function depends on not being invoked?</p>
  
  <p>I created this fiddle to test:</p>
  
  <p><a href="http://jsfiddle.net/bJK98/" rel="noreferrer">http://jsfiddle.net/bJK98/</a></p>
  
  <pre><code>var ViewModel = function(first, last) {
      this.firstName = ko.observable(first);
      this.lastName = ko.observable(last);
      this.condition = ko.observable(false);
  
      // at the point of evaluation of this computed observabled, 'condition'
      // will be false, yet the dependecy to both firstName and lastName is
      // identified
      this.fullName = ko.computed(function() {
          return this.condition() ? this.firstName() : this.lastName();
      }, this);
  };
  </code></pre>
  
  <p>However, somehow Knockout correctly identified the dependency to both <code>firstName</code> and <code>lastName</code>.</p>
  
  <p>Can anyone explain how?</p>