How can you pass arguments to a function when implementing the Revealing module pattern in JavaScript. I have a module like this
var GlobalModule = (function() {
function consoleLog(textToOutput) {
console.log(textToOutput);
}
return {
consoleLog: consoleLog()
};
})();
Later on, when i run GlobalModule.consoleLog("Dummy text");, I get undefined as the output.
return {
consoleLog: consoleLog()
};
That part of your code is wrong. You're exporting the Result of the consoleLog call due to the () at the end of the function, where you want to export the function itsself. So just remove the function call:
return {
consoleLog: consoleLog
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With