According to feedback received and in line with the principles of JavaScript
For more information, check out this helpful resource
Understanding function invocation
Merely defining a function does not automatically run it. When a function is defined, it simply assigns a name to the function and outlines what actions to take when it is called upon. The actual execution of the defined function happens when it is invoked with the specified parameters. For instance, if you create a function named "square," you would call it like this:
square(5);
Note that the execution of the function requires the use of parentheses ().
function square(num){
return num;
}
console.log(square);
=> function square(num)
console.log(square( 5 ));
=> 5
In your case where you are utilizing a factory pattern,
console.log(EventService);
=> { test: function() { return 'It Works!'; }
As per the scenario, your factory function has returned an object containing the property test which refers to an anonymous function.
Simply invoking EventService.test will return the anonymous function, similar to how console.log(square); displayed the function definition. To make use of the function's return value, remember to invoke it as follows
EventService.test();
Feel free to continue asking questions at any time, but also don't forget to troubleshoot your code independently first. If you still require assistance, ensure to provide details on the steps you've taken to debug the issue :)