I am not familiar with oops implementation in js specific code.
I saw this code
var RandomNumberGameViewModel = function () {
var self = this;
Level = function (id, identifier) {
return {
id: ko.observable(id),
identifier: ko.observable(identifier)
};
}
self.GenerateRandomNumber = function () {
var number = '';
for (var i = 0; i < self.digitsLimit() ; i++) {
var randomNumber = Math.floor((Math.random() * self.digitsLimit()) + 1);
number += randomNumber;
}
return number;
}
}
- What will be called
RandomNumberGameViewModel()
is it a name of any function? - I guess
Level()
is a function name then what isGenerateRandomNumber()
? If both are functions then why is one pre-fixed with self keyword and the other is not?
Please explain the code which I highlighted here.
Thanks