Currently, I am delving into the world of programming and stumbled upon this tutorial. While following along, I encountered an issue in the console displaying the error message
ReferenceError: Logger is not defined --> }(Logger))
. It seems that the discrepancy between the tutorial's code and mine lies in the use of underscore's extend versus the extend method (function) that I opted for from another source.
function extend(destination, source){
for(var k in source){
if(source.hasOwnProperty(k)){
destination[k] = source[k];
}
}
return destination;
}
(function () {
var Logger = {
log: function (message) {
if (window.console && typeof console.log === "function") {
console.log(message);
}
}
};
return Logger;
}());
(function ( Logger) {
var MyObject = function () {
this.doSomething = function () {
this.log("My Object is doing something!");
};
};
// This copies the members of the `Logger` object onto the prototype of `MyObject`
extend(MyObject.prototype, Logger);
return MyObject;
}(Logger))
var obj = new MyObject();
obj.doSomething();
Perhaps my struggle lies in grasping the usage of self-invoking anonymous functions.