Hello there! I'm new to JavaScript and currently working on a basic JavaScript module.
var starrySky = (function () {
var defaults = {}
var validate = {
argNum: function (arg, num) {
if (arg != num) {
throw new Error('invalid argument count');
};
}
}
return {
event: function (elementName, eventName, functionName) {
validate.argNum(arguments.length, 3);
if (elementName.addEventListener) {
elementName.addEventListener(eventName, functionName, false);
} else {
elementName.attachEvent("on" + eventName, functionName);
}
}
};
})();
When I use it like this:
starrySky.event("", document, "DOMContentLoaded", function() {
console.log("DOM loaded");
});
The error line in the console says:
Is there a way to display an error message within the function call when there are 4 arguments instead of 3?