-1

just see the two approach and tell me what is the difference. when which one should use ? in first case instance will be created but in second case no instance will be created at the time of ko.applyBindings() so here is the code.

function MyViewModel() {
         var self = this;
         self.lastInterest = ko.observable();
         self.places = ko.observableArray(['London', 'Paris', 'Tokyo']);

         // The current item will be passed as the first parameter, so we know which place was hovered over
         self.logMouseOver = function(place) {
             self.lastInterest(place);
         }
     }
     ko.applyBindings(new MyViewModel());


var viewModel = {
        detailsEnabled: ko.observable(false),
        enableDetails: function() {
            this.detailsEnabled(true);
        },
        disableDetails: function() {
            this.detailsEnabled(false);
        }
    };
    ko.applyBindings(viewModel);
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • another small question that is knockout js is the library developed by google because when i go to knockout js forum then url looks like groups.google.com/group/knockoutjs. – Thomas Nov 20 '13 at 11:08

1 Answers1

-2

first code part is a function but second is a class based module design pattern code witch you can reach to parameters in second code !

check out this :

http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html