-1

I am going over someone else's code and trying to understand what they have done. There are terms in there that I have no idea what they are.. Prototype, subscribe?? Can someone help me in understanding what this function is doing?

Thanks

myspace.prototype.attached = function () {
    var that = this;
    this.appViewModel.dataLoaded.subscribe(function (val) {
        window.setTimeout(function() {
            that.showUI(val);
        }, 300);
    }, this);
};
Sarah
  • 1,199
  • 2
  • 21
  • 42

1 Answers1

0

All JavaScript objects inherit properties and methods from a prototype. You can find more info here: https://www.w3schools.com/js/js_object_prototypes.asp

And for subscribe. Please read the documentation of knockout here: http://knockoutjs.com/documentation/observables.html

In simple words, subscribe is quite similar with computed function, except it will only listen to changes in only 1 observable while computed function will listen to changes in every observables inside it. In your example: If the dataLoaded change, the part inside it will be called

vicnoob
  • 1,169
  • 13
  • 27
  • Thank you, thank you, thank you so much for this answer Vicnoob. That is very helpful and get me started. I will read more to this and post more questions as I make progress. Thanks again. – Sarah Apr 21 '18 at 05:44