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.
Do with function inside the return object
var GlobalModule = (function() {
return {
consoleLog: function(textToOutput)
{
console.log(textToOutput);
}
}
})();
GlobalModule.consoleLog("Dummy text");
Simply Do like this same output achieved . object => function call
.No need a return object
var GlobalModule ={
consoleLog: function(textToOutput) {
console.log(textToOutput);
}
}
GlobalModule.consoleLog("Dummy text");