I've been reading Game Design with HTML5 and JavaScript and it introduced me to objects. So after reading the book and working on the projects I decided to take this new found knowledge and integrate objects in my own projects. So here's my question can or should objects call their own functions? For example:
var someObject = {
start: function() {
check();
},
check: function() {
console.log("Check!");
}
};
someObject.start();
The book did show an example with a timer that does this:
var timer = {
start: function() {
var self = this;
window.setInterval(function(){self.tick();}, 1000);
},
tick: function() {
console.log('tick!');
}
};
In the example with timer object it makes a reference to self in order to call the internal function, so does this mean I should use self to call internal functions or is this the proper way to do this with objects? Or best practices? Thanks in advance.
var someObject = {
start: function() {
var self = this;
self.check();
},
check: function() {
console.log("Check!");
}
};
someObject.start();