Open surfmuggle opened 3 years ago
Without modules a function expression that is immediately invoked can be used:
const weekDay = function() {
const names = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
return {
name(number) { return names[number]; },
number(name) { return names.indexOf(name); }
};
}();
Example how to use it console.log(weekDay.name(weekDay.number("Sunday")));
. The const weekDay has two functions name(number)
and number(name)
.
A module is a piece of program that specifies which other pieces it relies on and which functionality it provides for other modules to use (its interface). source Eloquent JavaScript - Modules